Skip to content

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

@hattesen

Description

@hattesen

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions