I have a JSON response where one of the keys value is holding "-", "," and space inside it. I was able to parse it correctly but now it does not seem to be working.
For replication, we can use http://jsonpath.com/
JSON:
{
"data":{
"ID":"123",
"paraValues":{
"DE:is this A": "Yes",
"DE:is this B": "No",
"DE:Is project part of a multi-piece initiative - campaign, event?" : "No"
}
}
}
I am trying to fetch the value of this key : "DE:Is project part of a multi-piece initiative - campaign, event"
I am using:
$.data.paraValues.DE:Is project part of a multi-piece initiative - campaign, event?
It didn't work.
Then I used after reading some answers:
$.data.paraValues.["DE:Is project part of a multi-piece initiative - campaign, event?"]
This also didn't work.
Update: Those who are coming here from java, issue can be resolved by upgrading the jsonpath library.
I added below library and it resolved the issue :
<!-- https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.7.0</version>
</dependency>
Note: in http://jsonpath.com/, accessing it is still failing.