Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you escape the @ symbol in jsonpath?

Tags:

json

jsonpath

Given a json list like this:

    {    
 "listRel:customFieldList": {
            "platformCore:customField": [
              {
                "@internalId": "801",
                "scriptId": "custentity_admin_contact_cweb",
                "@xsi:type": "platformCore:BooleanCustomFieldRef",
                "platformCore:value": "false"
              },
              {
                "@internalId": "712",
                "@scriptId": "custentity_bar_number",
                "@xsi:type": "platformCore:StringCustomFieldRef",
                "platformCore:value": "166493"
              },
              {
                "@internalId": "798",
                "@scriptId": "custentity_contact_type",
                "@xsi:type": "platformCore:SelectCustomFieldRef",
                "platformCore:value": {
                  "@internalId": "1",
                  "@typeId": "148",
                  "platformCore:name": "Attorney"
                }
              }
              ]
 }
}

How can I select the value in "custentity_bar_number"? 166493?

This will get you there, but only if you delete the @ symbol in front of @scriptId in the JSON.

$..['platformCore:customField'][?(@['scriptId'] == 'custentity_bar_number')]

So what I need is a way to escape the @ symbol in the json, and make something like this work:

$..['platformCore:customField'][?(@['@scriptId'] == 'custentity_bar_number')]

I am using http://jsonpath.com/ to try and make this work.

like image 511
redwards510 Avatar asked May 13 '16 23:05

redwards510


1 Answers

You apparently need to use the hex code (I think it has something to do with the way the expression is being parsed)

$..['platformCore:customField'][?(@['\x40scriptId'] == 'custentity_bar_number')]
like image 151
Jonathan Gray Avatar answered Sep 27 '22 00:09

Jonathan Gray