Java – Query language for JSON

javajson

I have a server which is returning very big JSON message and my client application is only dependent on part of this response. Client application needs to check if "xyz" property exist in JSON message and depending on the result run a specific usecase.

For this requirement converting the whole JSON message to object sounds bit expensive to me and hence this question.

Is there a standard JSON query language like one we have for XML? If yes what are best know implementation of this query language in java.

FYI : Changing or adding new service on server side is not an option.

Best Answer

Why not just use javascript? (JSON is Javascript Object Notation after all). You then won't have to parse or manipulate the JSON.

EDIT Have a look at http://json.org/java

For this requirement converting the whole JSON message to object sounds bit expensive to me and hence this question.

It isn't. Deserializing an object is cheap (bench test it yourself). Talking to the external API will be an order of magnitude more expensive. You could directly manipulate the string which might be slightly faster but you would risk bugs, reduce extensibility and reduce readability. A high cost.

Related Topic