0

Here is my JSON object, Obj3:

{
    "cars": {
        "Nissan": [
            {"model":"Sentra", "@doors":4},
            {"model":"Maxima", "@doors":4},
            {"model":"Skyline", "@doors":2}
        ],
        "Ford": [
            {"model":"Taurus", "@doors":4},
            {"model":"Escort", "@doors":4}
        ]
    }
}

I'm having an issue with the @ symbol before doors. If I don't have the @ symbol (i.e the key is just doors), I can use something like the below to work as a sort of if statement:

console.log(JSONPath(JSONPath.toPathString(['$', 'cars', 'Nissan[?(@.doors==4)]']),obj2));

This returns:

{ model: 'Sentra', doors: 4 }, { model: 'Maxima', doors: 4 } ]

Can anyone advise how I need to change this to account for @doors as the key as opposed to doors?

Tried escaping with \x40 but had no success

nimgwfc
  • 1,294
  • 1
  • 12
  • 30

1 Answers1

0

The following JSON Path expression should do the trick:

$.cars.Nissan[?(@['@doors'] == 4)]
cassiomolin
  • 124,154
  • 35
  • 280
  • 359