JsonPath Query [Answered]
I have some json that looks like this:
Using a JsonPath query, I want to filter results where
IsActive
is true and return the TeamName. I have put together this query:
The way I read it, it should select from teams where IsActive is true, then return the TeamName property, however the resulting teams
object is always null (specifically, for whatever reason it returns List<JsonElement?>?
). Removing the .TeamName
reference at the end also returns a null collection. According to this stackoverflow post, the JsonPath query is properly formatted (https://stackoverflow.com/questions/46931964/json-path-to-check-equals-condition).
Any thoughts of what I might be doing wrong here? I'm using System.Text.Json and the JsonDocumentPath libraries.Stack Overflow
JSON Path to check equals condition
I am a newbie to Json Path. I am using Apache camel along with the json path. I am trying to check the json path success to evaluate the value to true.
Json Message:
{
"success": true,
"
7 Replies
Don't do it this way. Map the JSON to a class and deserialize it using
Newtonsoft
i.e.
something like that.maybe you can try https://json-everything.net/json-path
json-everything.net
Extended JSON support in .Net built on top of the System.Text.Json namespace
I'm needing to do the json path because if I use code like yours, I get a json parse exception when deserializing because of how S.T.J handles the teams node. That said, even moving the IsActive and TeamName to C#, I get this:
I'll give this library a try. I had been using a different json path library
Wtf is STj
Your getting a exception because your doing something wrong
System.Text.Json, the .net json parsing library.
The code you provided was for Newtonsoft.Json
Json-Everything worked.
I can show you later today when I have time but your overcomplicating that code majorly
✅ This post has been marked as answered!