Skip to content

[feature] Path to matched values #19

@niflostancu

Description

@niflostancu

jsonpath2 version

0.1.0

Scenario:

Hi.

I need to get the full path to a matched value. Primarily, because I need to modify it.

Example:
Let's say we have:

{"values": [
    {"type": 1, "value": 2},
    {"type": 2, "value": 3},
    {"type": 1, "value": 10},
]}

Currently, if I use an expression to match some values (e.g., "$.values.*[?(@.type = 1)].value"), it will return MatchData objects containing several properties (current_value is the string that I wish to get the path / modify) but none of them allow me to rebuild the full path to that value.

Expected Result:

I would like to be able to either get the full root path as a list of keys (e.g., ["values", 0, "value"]), or having a MatchData object provide a reference to the parent object and its matched key name (e.g., reference to the {"type", "value"} object + the matched "value" key).

I can come with a pull request if you can tell me the preferred way of implementing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions