JSONPath-Plus / JSONPath

A fork of JSONPath from http://goessner.net/articles/JsonPath/
Other
963 stars 169 forks source link

Escaping is not seemed to work properly #137

Closed MJ-DEV91 closed 3 years ago

MJ-DEV91 commented 3 years ago

Hi. There's a field inside the JSON which contains '@', and now I want to escape it. Assume below JSON:

{
    "id": "1234",
    "items": [
        {
            "id": "i123",
            "item": {
                "id": "789",
                "@type": "Person",
                "name": "Find me!!"
            }
        }
    ]
}

I wanna access the name (items.item.name) with a Query:

$.items[?(@.item.`@type` === 'Person')].item.name

I put @type inside the backticks, but it's not working.

If I had "type" instead of "@type", the below query works fine:

{
    "id": "1234",
    "items": [
        {
            "id": "i123",
            "item": {
                "id": "789",
                "type": "Person",
                "name": "Find me!!"
            }
        }
    ]
}
$.items[?(@.item.type === 'Person')].item.name
[
    "Find me!!"
]

Desktop**

brettz9 commented 3 years ago

$.items[?(@.item['@type'] === 'Person')].item.name appears to be working for me. In looking at source, it appears that @ is only manipulated if folowed by any of .\s)[.

MJ-DEV91 commented 3 years ago

$.items[?(@.item['@type'] === 'Person')].item.name appears to be working for me. In looking at source, it appears that @ is only manipulated if folowed by any of .\s)[.

Thank you. it looks like I didn't do it correctly.

brettz9 commented 3 years ago

We haven't clearly documented it, and we really need a proper parser in the first place to make this all more consistent, e.g., so you could use backticks anywhere. But glad it worked out.