FlowCommunications/JSONPath

@-Operator in queries doesn't accept [] to select child elements

Closed this issue · 0 comments

To use queries in JSONPath, one needs to use the ?() operator. Inside a script the [] (brackets) do not work as child selectors. This is needed for lists in the JSON, however.

Working Example

The following is the original JSON:

{
    "result": {
        "list": [
            {
                "time": 1477526400,
                "o": "11.51000"
            },
            {
                "time": 1477612800,
                "o": "11.49870"
            }
        ]
    }
}

I want to select the objects that have o == "11.51000"(ie. the first set of values). The following JSONPath gets the proper result:

$.result.list[?(@.o == "11.51000")]

This is the expected result:

[{"time":1477526400, "o":"11.51000"}]

Non-working example

If, however, the original JSON is not a list of objects, but a list of lists, I cannot get the same result.

{
    "result": {
        "list": [
            [
                1477526400,
                "11.51000"
            ],
            [
                1477612800,
                "11.49870"
            ]
        ]
    }
}

Because the items in the lists aren't named, I need to access them with []. Thus, I would expect this JSONPath to produce the result:

$.result.list[?(@[1] == "11.51000")]

It returns an error instead.

Both path expressions have been tested with https://jsonpath.curiousconcept.com/ set to JSONPath 0.3.4.