14

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.

redwards510
  • 1,802
  • 1
  • 17
  • 23

1 Answers1

7

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')]
Jonathan Gray
  • 2,509
  • 15
  • 20
  • Wow! great job! I had no idea you could insert codes like that, it's not in the semi-official documentation http://goessner.net/articles/JsonPath/index.html#e2 – redwards510 May 16 '16 at 16:17
  • I tried to directly select a value with a key that contains @. and this didn't work for me (neither did anything else, brackets, quotes, escaping... ) – zslim Dec 15 '20 at 08:43