09-18-2020 08:49 AM
0
I am attempting get a value based on the key containing @ symbol fails using JSONPath.
Cause: Since @ is the current object/element, json does not return the value.
Sample 1: { “firstName”: “John”, “lastName” : “doe”, “phoneNumbers”: [ { “type” : “iPhone”, “number”: “0123-4567-8888” }, { “type” : “home”, “number”: “0123-4567-8910” } ] }
This works: $.phoneNumbers[1].type
This works: $.phoneNumbers[?(@.type==“iPhone”)].type
Sample2: { “firstName”: “John”, “lastName” : “doe”, “phoneNumbers”: [ { “**@type" : “iPhone”, “number”: “0123-4567-8888” }, { "@**type” : “home”, “number”: “0123-4567-8910” } ] }
This works: $.phoneNumbers[1].type
But this does not work: $.phoneNumbers[?(@.@type**==“iPhone”)].type**
Any advice for dealing with keys and values containing @ characters?
Solved! Go to Solution.
09-18-2020 10:04 AM
I believe this expression will give you the filter you are looking for:
jsonPath($.phoneNumbers, "[?(jsonPath(@, '@**type') == 'iPhone')]")
if you’d like to collect the ‘@**type’ values then this is the expression you are looking for:
jsonPath($.phoneNumbers, "[?(jsonPath(@, '@**type') == 'iPhone')].@**type")
09-18-2020 10:04 AM
I believe this expression will give you the filter you are looking for:
jsonPath($.phoneNumbers, "[?(jsonPath(@, '@**type') == 'iPhone')]")
if you’d like to collect the ‘@**type’ values then this is the expression you are looking for:
jsonPath($.phoneNumbers, "[?(jsonPath(@, '@**type') == 'iPhone')].@**type")
09-18-2020 10:59 AM
Thank you!