vishalsirsodiya / jsonpath

Automatically exported from code.google.com/p/jsonpath
0 stars 0 forks source link

using '@' in a property name breaks it. #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Using this object
{"@position": '18',
"@unid": '29CD471ED18EE9B88725740E0006853D',
"@noteid": '982',
"@siblings": 51,
entrydata: [
{
"@columnnumber": 0,
"@name": 'first',
text: {
0: 'test3'
}
},
{
"@columnnumber": 1,
"@name": 'last',
text: {
0: 'last3'
}
},
{
"@columnnumber": 2,
"@name": 'company',
text: {
0: 'company3'
}
},
{
"@columnnumber": 3,
"@name": 'email',
text: {
0: 'email3@gmail.com'
}
},
{
"@columnnumber": 4,
"@name": 'time',
text: {
0: '3:00 PM'
}
}
]
}

2. using this xpath does not work
jsonPath(obj, "entrydata[?(@['@name']=='first')].text[0]")

3. if I rename the property '@name' to 'name' it works

I am working with a server side response that i cannot alter... any ideas?

Original issue reported on code.google.com by bhaid...@gmail.com on 17 Mar 2008 at 7:24

GoogleCodeExporter commented 9 years ago
Resolved with JSONPath 0.8.5 (see Source section).

The '@' character can now be used within member names, if it is escaped by an 
backslash.

So changing your call to

jsonPath(obj, "entrydata[?(@['\\@name']=='first')].text[0]");

works now with JSONPath 0.8.5+.

Thanks.

Original comment by ste...@goessner.net on 30 Mar 2008 at 6:39

GoogleCodeExporter commented 9 years ago
why we need to escape such a commonly used sign?

my fix will work for(base on 0.8.5)

jsonPath(obj, "entrydata[?(@['@name']=='first')].text[0]");

Original comment by lauxp1...@gmail.com on 1 Oct 2013 at 4:17

GoogleCodeExporter commented 9 years ago
forget the attach patch file?

Original comment by lauxp1...@gmail.com on 1 Oct 2013 at 4:18

Attachments: