JSONPath-Plus / JSONPath

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

Cannot resolve JSONPath has single quote #203

Open superdc opened 7 months ago

superdc commented 7 months ago

Describe the bug

Code sample or steps to reproduce

// Code that reproduces problem here
const json = {
    "firstName": "John",
    "'lastName'": "doe",
    "address": {
        "streetAddress": "naist street",
        "city": "Nara",
        "postalCode": "630-0192"
    },
    "phoneNumbers": [
        {
            "type": "iPhone",
            "number": "0123-4567-8888"
        },
        {
            "type": "home",
            "number": "0123-4567-8910"
        }
    ]
}

const normalizedPaths = JSONPath({ path: `$["'lastName'"]`, json, resultType: 'path', wrap: false })

Console error or logs

Expected behavior

Expected result

now normalizedPaths is undefined expected normalizedPaths should be $["'lastName'"]

Environment (IMPORTANT)

Desktop**

juanreynolds commented 6 months ago

Also getting that. This however works:

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

    const normalizedPaths = JSONPath({ path: `$['"lastName"']`, json, resultType: 'path', wrap: false });