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.

  • In javascript, if the response is sent with the correct header (application/json), the JSON response will be a javascript object. Is that what you're asking for? I'm not sure from your question. – Florian Margaine Feb 15 '12 at 9:23
  • @Florian I agree, Let me update my question and make it java specific. – Farm Feb 15 '12 at 9:26
  • Then, I guess you have tried json.org/java ? :-) – Florian Margaine Feb 15 '12 at 9:31
  • I've been wondering the same thing. Every Java library for JSON I've seen appears to be horribly bulky; is there nothing along the lines of JSON.getString(json_string, 'foo.22.bar') (for, property "bar" in the 22 element of list at property "foo", which contains a String) – Izkata Feb 15 '12 at 22:18
  • Or, to avoid parsing each time, JSON baz = new JSON(json_string); baz.getString('foo.22.bar');, for example – Izkata Feb 15 '12 at 22:19

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.

| improve this answer | |
  • I updated my question and made it Java specific. – Farm Feb 15 '12 at 9:28
  • Using javascript is not an option since client application is running on Headunit which only has LWUIT support – Farm Feb 15 '12 at 19:23

"Measure, don't guess". Yes object serialisation and deserialisation my be expensive in theory, but what are the performance goals of your application? If the object (de)serialisation doesn't push your performance to unacceptable levels, then don't worry about it :-). The key of course is to know what the performance boundaries should be (e.g. Response time to user in 2 seconds) and to measure each part of the request/response cycle.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.