Daniël van den Berg Daniël van den Berg - 1 year ago 88
JSON Question

Compare two JSONObjects

I'm having preformance issues while comparing two

. My current method of comparison is as followed:

return o1.toString().equals(o2.toString())

However, this is slow. I can't seem to find any other way to properly compare two JSONObjects though.
can be different, while the string is the same. Going through every element and comparing those individually seems tediously slow as well.

Is there any way to compare two JSONObjects faster?

This question is specifically about the use of org.json as supplied by http://json.org/. I really want to refrain from using any other libraries like the ones mentioned in Compare two JSON objects in Java, as this library is critical to some parts of the application.

Answer Source

As I can see json.org has JSONObject.similar method. It is recursive, but you do not create any objects. You compare already existing objects. You can compare performance between toString + equals and JSONObject.similar

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download