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 (ie 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
以下JSON Path表达式可以解决问题:
$.cars.Nissan[?(@['@doors'] == 4)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.