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

Determine support for "terminal tilde" for extracting keys #151

Open
hattesen opened this issue Nov 5, 2024 · 2 comments
Open

Determine support for "terminal tilde" for extracting keys #151

hattesen opened this issue Nov 5, 2024 · 2 comments

Comments

@hattesen
Copy link

hattesen commented Nov 5, 2024

Quite a few JSONPath implementations support "terminal tilde" notation to extract object keys (rather than values), but I have come across issues raised on a few, that do NOT support the "terminal tilde" notation, while searching for any formal description of the notation.

It would be nice to have the "terminal tilde" support included in the json-path-comparison overview.

Examples evaluated using JSONPath online evaluator:

{
    "firstName": "John",
    "lastName": "doe",
    "age": 26,
    "address": {
        "streetAddress": "naist street",
        "city": "Nara",
        "postalCode": "630-0192"
    },
    "phoneNumbers": {
        "mobile": {
            "type": "iPhone",
            "number": "0123-4567-8888"
        },
        "work": {
            "type": "land line",
            "number": "0123-4567-8910"
        }
    }
}

To extract the keys of the address object, you would evaluate the JSONPath expression $.address.*~ or $.address[*~] resulting in:

[
  "streetAddress",
  "city",
  "postalCode"
]

To extract the keys of the phoneNumbers object, you would use the JSONPath expression $.phoneNumbers.*~ or $.phoneNumbers[*~], resulting in:

[
  "mobile",
  "work"
]

The only specification documentation of the "terminal tilde" JSONPath notation that I have been able to locate is https://github.com/json-path/JsonPath#functions

Function: keys()
Description: Provides the property keys (An alternative for terminal tilde ~)
Output type: Set<E>

@hattesen
Copy link
Author

hattesen commented Nov 5, 2024

Here are a couple of links to issues regarding keys() and "terminal tilde" support in the JsonPath GitHub repository:

@danielaparker
Copy link
Collaborator

danielaparker commented Nov 5, 2024

@hattesen, I agree that it should be included in the comparisons, it's supported in the most widely used javascript implementation, I'd suggest submitting a pull request that covers this feature for @cburgmer's consideration.

Fork the repository and in the queries directory, create a new subdirectory with a name that follows the conventions, something like "terminal_tilde_for_extracting_keys". Include two files, document.json and selector, that contain the JSON document and JSONPath selector respectively.

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

No branches or pull requests

2 participants