I am trying to compare two JSON strings. Below is my code in Java:
String json1 = "C:\\test1.json";
String json2 = "C:\\test2.json";
Gson g = new Gson();
Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> firstMap = g.fromJson(json1, mapType);
Map<String, Object> secondMap = g.fromJson(json2, mapType);
System.out.println(Maps.difference(firstMap, secondMap));
and below is my JSON file format
My Json 1
{
"00601":{
"type":"zipcode",
"assignment":"South Monroe, MI"
},
"00602":{
"type":"zipcode",
"assignment":"South Monroe, MI"
},
"00603":{
"type":"zipcode",
"assignment":"South Monroe, MI"
}
}
My Json 2
{
"00601":{
"type":"zipcode",
"assignment":"South Monroe, MI"
},
"00602":{
"type":"zipcode",
"assignment":"South Monroe, MI"
},
"00603":{
"type":"zipcode",
"assignment":"South Monroe, MI"
}
}
I have gone through JSON Error "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"
but still facing the issue:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING