Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot resolve JSONPath has single quote #203

Open
superdc opened this issue Jan 28, 2024 · 2 comments
Open

Cannot resolve JSONPath has single quote #203

superdc opened this issue Jan 28, 2024 · 2 comments

Comments

@superdc
Copy link

superdc commented Jan 28, 2024

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)

  • JSONPath-Plus version: 7.2.0

Desktop**

  • OS: MacOS
@juanreynolds
Copy link

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 });

@80avin
Copy link
Contributor

80avin commented Sep 30, 2024

A workaround path for original document is : $[''lastName'']
i.e.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants