JSONPath-Plus / JSONPath

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

Path not found when square Brackets inside of Path String #167

Open Hugo2128 opened 2 years ago

Hugo2128 commented 2 years ago

Describe the bug

Using a string with square brackets inside as Path returns undefind even if the Path is there.

Code sample or steps to reproduce

Example:

{
    "firstName": "John",
    "lastName": "doe",
    "age": 26,
    "address": {
        "streetAddress": "naist street",
        "city": "Nara",
        "postalCode": "630-0192"
    },
    "phoneNumbers [1]": [
        {
            "type": "iPhone",
            "number": "0123-4567-8888"
        },
        {
            "type": "home",
            "number": "0123-4567-8910"
        }
    ]
}

Now i want to get "phoneNumbers [1]" with

path: $..['phoneNumbers [1]'] or
path: $..'phoneNumbers [1]' or
path: $..phoneNumbers [1]

returns No Match

Expected result

[
  [
    {
      "type": "iPhone",
      "number": "0123-4567-8888"
    },
    {
      "type": "home",
      "number": "0123-4567-8910"
    }
  ] 
]

Environment (IMPORTANT)

Desktop**

Additional context

When removing the square brackets everything works fine even when replacing them curly braces or parentheses

aodinok commented 1 year ago

Can confirm it, have exactly the same issue