1

I need to print the difference between two json array i am using

Type mapType = new TypeToken<Map<String, Object>>() {
    }.getType();
Map<String, Object> firstMap = g.fromJson(jsonElement1, mapType);
Map<String, Object> secondMap = g.fromJson(jsonElement2, mapType);
MapDifference diff = Maps.difference(firstMap, secondMap);

The above code was working fine if it a json string object, but it is throwing error

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 now.

How to print the difference between these two json array

OH GOD SPIDERS
  • 3,091
  • 2
  • 13
  • 16
  • It would be helpful to include the JSON arrays you're testing on. – px06 Feb 15 '17 at 09:51
  • @px06 that is very large –  Feb 15 '17 at 10:06
  • @px06 this is a sample [{"ind":"","Cars":[{"His":[{"cost":0.0,"charge":0.0,"start":{"code1":"B","sCode":"A","dateTime":"Feb 11, 2017 8:00:58 AM","cNote":"","vStation":{"s33":"BECKER","a.....}]]] –  Feb 15 '17 at 10:10
  • You should probably use an appropriate tool for this complex task. something like [what is suggested on Software Recommendations](http://softwarerecs.stackexchange.com/q/17812/26414). – Olivier Grégoire Feb 15 '17 at 10:34
  • Possible duplicate of [Getting a diff of two JSON strings using Java code](http://stackoverflow.com/questions/3214108/getting-a-diff-of-two-json-strings-using-java-code) – Olivier Grégoire Feb 15 '17 at 10:35

1 Answers1

1

Here's a related question which should provide you with direction: https://softwarerecs.stackexchange.com/questions/17812/java-library-that-diffs-json-and-generates-what-was-added-deleted-modified

Community
  • 1
  • 1
endaS
  • 31
  • 6