SEARCH
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Premier
Posts: 126
Registered: ‎04-25-2014
Accepted Solution

json path: How to if attribute/property has special character?

I have following json string, how should I contruct my jsonpath for the "break?" attribute?

[{
"id":2344,
"exam_id":4863,
"time_allowed":900,
"name":null,
"introduction":null,
"order":10,
"break?":true,
"content_location":null
}]

 

I tried following but none works:

$.[?(@.'break?'=='true')]

$.[?(@.['break?']=='true')]

 

Appreciate it.

Jun

 

SOASTA Employee
Posts: 922
Registered: ‎07-17-2011

Re: json path: How to if attribute/property has special character?

Hi Jun,

 

If you want to get the value of break, the try the below:

 

$..break?

 

If you want to get the whole block, try the below:

 

$..[?(@.break? == 'true')]

 

If you want to get a specific parameter when break? is equals to true, then just add that parameter at the end of the above JSONPath, for instance for getting the id:

 

$..[?(@.break? == 'true')].id

 

Regards,

 

Salvador

Premier
Posts: 126
Registered: ‎04-25-2014

Re: json path: How to if attribute/property has special character?

Hi Sal,

 

Thanks for the response, I never thought $..break? would have worked but it did.....unfortunately, the other two don't, at least with a couple of online json path testers such as http://www.jsonquerytool.com/. Any other idea?

 

Jun

SOASTA Employee
Posts: 922
Registered: ‎07-17-2011

Re: json path: How to if attribute/property has special character?

Have you tried them in CloudTest? Sometimes the JSONPaths in online testers don't work, but they work in CloudTest.

 

Regards,

 

Salvador

Premier
Posts: 126
Registered: ‎04-25-2014

Re: json path: How to if attribute/property has special character?

Yea, I tried but returned null.

SOASTA Employee
Posts: 922
Registered: ‎07-17-2011

Re: json path: How to if attribute/property has special character?

Hi Jun,

 

Not sure why you are getting null as I tested the JSONPaths I shared in CloudTest and they returned a value. But I only used the piece of response you gave in CloudTest. Is the complete response a pure JSON response? Is it possible to can share the whole JSON Response?

 

Regards,

 

Salvador

Premier
Posts: 126
Registered: ‎04-25-2014

Re: json path: How to if attribute/property has special character?

Hi Sal,

 

The $..break? works but $..[?(@.break? == 'true')] does not. Attached please find the response.

 

Thanks,

Jun

SOASTA Employee
Posts: 922
Registered: ‎07-17-2011

Re: json path: How to if attribute/property has special character?

Hi Jun,

 

It looks like I am going to need the clip since for me it is working with the reponse you provided (see below). Are you testing it in playback or in the Recorded Response? 

 

$..[?(@.break? == 'true')]

 

JSONPath.png

 

Can you please export the clip and share?

 

Regards,

 

Salvador

 

 

Premier
Posts: 126
Registered: ‎04-25-2014

Re: json path: How to if attribute/property has special character?

It's working now, I probably had a typo or something in the JSON path before. Appreciate your help. Jun