I'm trying to return the full parent object when the url = 'www.fruits.com'
Below is the json schema. It's quite tricky
{
"produce": [
{
"type": "fruit",
"upc": {
"code": {
"codingList": [
{
"item": "apple",
"organizations": [
{
"url": "www.fruits.com"
}
]
}
]
}
}
},
{
"type": "fruit",
"upc": {
"code": {
"codingList": [
{
"item": "tomato",
"organizations": [
{
"url": "www.special-fruits.com"
}
]
}
]
}
}
}
]
}
Any help would be much appreciated.
i've tried several different method on jsonpath.com but have not been able to crack it.
Conditionally returning the root value isn't supported in JSON Path. The only way to get the root is with the path
$
, which doesn't allow conditions.Assuming that you mean that you want the items in the
parents
that have aurl
with valuewww.fruits.com
, you can use this:You can test this on https://json-everything.net/json-path, which implements the upcoming IETF spec for JSON Path.
https://jsonpath.com/ doesn't seem to support
@
very well. It appears that it requires a subquery, e.g.@.foo
.