Skip to content

Failure to match "$..['$ref']", "$..['ref']", but succeeds on "$..ref" #43

@JRAndreassen

Description

@JRAndreassen

Hi...
I'm trying to use the JsonPath with OpenAPI files...
there is a lot of redirect references that I can't extract of the form:

{
...
 "$ref": "#/x/y/z",
...
}

Given the following JSON

{
    "Junk1": "This is a test to illustrate use of '$' in the attr for the expression $..['$ref'] ",
    "$ref": "Match Root",
    "Subset1":[
        {"Junk2": "Data...",
         "$ref": "Match Subset1"
        }
    ],
    "hierachy1":{
        "hierachy2.1":{
            "hierachy2.1.1":{ "$ref":"Match 2.1.1"},
            "hierachy2.1.2":{ "ref":"Match 2.1.2"},
            "hierachy2.1.3":{ "ref":"No Match 2.1.3"},
            "hierachy2.1.4":{ "$ref":"Match 2.1.4"},
            "hierachy2.1.5":{ "ref":"No Match 2.1.5"}
        },
        "hierachy2.2":{
            "hierachy2.2.1":{ "ref":"No Match 2.2.1"},
            "hierachy2.2.2":{ "$ref":"Match 2.2.2"},
            "hierachy2.2.3":{ "ref":"No Match 2.2.3"},
            "hierachy2.2.4":{ "ref":"No Match 2.2.5"},
            "hierachy2.2.5":{ "$ref":"Match 2.2.5"}
        },
        "hierachy2.3":{
            "hierachy2.3.1":{ "ref":"No Match 2.3.1"},
            "hierachy2.3.2":{ "ref":"No Match 2.3.2"},
            "hierachy2.3.3":{ "ref":"No Match 2.3.3"},
            "hierachy2.3.4":{ "ref":"No Match 2.3.4"},
            "hierachy2.3.5":{ "ref":"No Match 2.3.5"},
            "hierachy2.3.6":{
                "hierachy2.3.6.1":{ "$ref":"Match 2.3.6.1"},
                "hierachy2.3.6.2":{ "ref":"No Match 2.3.6.2"},
                "hierachy2.3.6.3":{ "ref":"No Match 2.3.6.3"},
                "hierachy2.3.6.4":{ "ref":"No Match 2.3.6.4"},
                "hierachy2.3.6.5":{ "ref":"No Match 2.3.6.5"}
                }
            }
    }
}

Using the online JasonPath evaluator, The expressions "$..['$ref']", "$..[$ref]", "$..$ref" should yeild:
The

Select: [String("Match Root")
String("Match Subset1"),
String("Match 2.1.1"),
String("Match 2.1.4"),
String("Match 2.2.2"),
String("Match 2.2.5"),
String("Match 2.3.6.1")]

the expression "$..$ref" causes an error:
Select: Err(path error:
$..
^^^
)

This works: "$..ref"

Select: [String("Match 2.1.2"), String("No Match 2.1.3"), String("No Match 2.1.5"), String("No Match 2.2.1"), String("No Match 2.2.3"), String("No Match 2.2.5"), String("No Match 2.3.1"), String("No Match 2.3.2"), String("No Match 2.3.3"), String("No Match 2.3.4"), String("No Match 2.3.5"), String("No Match 2.3.6.2"), String("No Match 2.3.6.3"), String("No Match 2.3.6.4"), String("No Match 2.3.6.5")]

I'll be happy to contribute, if you have some indicator on where to look/fix
JR

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions