cancel
Showing results for 
Search instead for 
Did you mean: 

JSONPath where key or value starts with @ character?

acesario
Contributor II

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?

1 ACCEPTED SOLUTION

cjhoward18
Employee
Employee

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")

View solution in original post

2 REPLIES 2

cjhoward18
Employee
Employee

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")

acesario
Contributor II

Thank you!