all. I'm having a really strange issue with https://github.com/json-path/JsonPath
One of the issues seems to be a re-entrant issue that the implentation has: when executing a path, each piece returns a string:
Expected to find an object with property ['ModuleListResponse'] in path $[0]['response'] but found 'java.lang.String'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
I've kind of "hacked" that by passing a JSONObject/JSONArray to JsonPath.read() instead of a JSON string. After doing that, now I'm getting:
Filter: [0]['name'] can only be applied to arrays. Current context is: [{"startLocation":{"types":["city"],"address":"Argentina","latitude":-34.6075682,"name":"Buenos Aires","description":"Buenos Aires is the capital and largest city of Argentina. The city is located on the western shore of the estuary of the Río de la Plata, o...449a049a781"}}]
As you can see, that's already an array. I've been googling a lot, but can't find what the issue is.
Regarding the code that's parsing it, there you have it:
jsonString = StringUtils.trim(jsonString);
if (jsonString.startsWith("[")) {
jsonObject = new org.json.JSONArray(jsonString);
} else {
jsonObject = new JSONObject(jsonString);
}
String jsonPath = "$[0].name";
Object jsonResult = JsonPath.using(conf)
.parse(jsonObject)
.read(jsonPath);
So, the question is: why JsonPath is reading the json as string, instead of json? And for the second issue, why it's not taking it as array, when it is clearly an array.