Reputation: 600
I have a complex JSON Structure . I wan't to exclude a part and get the list in two buckets. Say One as "inclusions" and another as "exclusions". Sample JSON is given below.
{
"Item": {
"Items": [{
"Items": [{
"category": "fruit",
"Item": {
"Items": [{
"Text": "Apple"
},
{
"Text": "Orange"
},
{
"Text": "Grapes"
},
{
"Text": "Guava"
}],
"Types": ["Value",
"Value",
"Value",
"Value"]
},
"Type": "Or"
},
{
"category": "fruit",
"Item": {
"Text": "Pineapple"
},
"Type": "Value"
}],
"Types": ["Constraint",
"Constraint"]
},
{
"category": "fruit",
"Item": {
"Text": "Banana"
},
"Type": "Value"
}],
"Types": ["Not",
"Constraint"]
},
"Type": "And"}
Here we have category fruits where We Apple,Orange ,Grapes and Guava are with "OR" and pineapple with "AND" Type and Banana is with "Not" .Once I Try
Item..Items[?(@.category='fruit')]..Text
It returns me
[ "Banana", "Apple", "Orange", "Grapes", "Guava", "Pineapple"]
But I want List to be
{["Apple", "Orange", "Grapes", "Guava", "Pineapple" ]
},{["Banana"]}
Is there a way in JSON Path to get something of similar structure
Upvotes: 2
Views: 883
Reputation: 3306
That may be not the answer you expected, but I don't think that's possible with JsonPath.
Quote from jayway/JsonPath
When evaluating a path you need to understand the concept of when a path is definite. A path is indefinite if it contains:
Indefinite paths always returns a list (as represented by current JsonProvider).
So your result will always be a list. What you already have is the closest you can get, I think.
Upvotes: 1