json-path-comparison
json-path-comparison copied to clipboard
Tests for root reference in filter expressions.
I found while answering a StackOverflow question that there aren't any tests checking for root reference in filter expressions:
$.SomeFieldB[?($.SomeFieldA == 'X')].SomeFieldC
for the JSON value
{
"SomeFieldA": "X",
"SomeFieldB": {
"SomeFieldC": "Y"
}
}
Note how the expression $.SomeFieldA == 'X'
refers back to the root, then takes the value of SomeFieldA
. This is a syntax which we have decided should be supported and is now in the JSON Path draft.
The closest query I can find is https://cburgmer.github.io/json-path-comparison/results/filter_expression_with_equals_with_root_reference.html which however compares the current value with the root value: $.items[?(@.key==$.value)]
.
Before we add your query, can I suggest to simplify? To me it seems to combine multiple scenarios:
- Dot notation
- Filter expression with root reference
- Filter expression on object
The last scenario isn't even supported uniformly I believe: $.SomeFieldB[?($.SomeFieldA == 'X')]
operates on the value "Y"
, compare https://cburgmer.github.io/json-path-comparison/results/filter_expression_on_object.html.
Sure, it was just the example in the question. Any filter query that references the root is fine.
I think the root reference you linked to covers this case. I'm going to close this.