title: How can i print differences, similarities and change in field names if any between 2 Json files in Kotlin?
body: <blockquote>
  <p>I have a JSON file/object 1 and  want to compare it with other JSON file/object and show the similarities,differences and change in field/key names or values if any in Kotlin.
  I know Comparable implementation but is there any other library would ease this task and reduce complexity.</p>
  <p>I'm concern about how to show differences and similarities per key and values in each JSON.
  i tried in java using JSONParser implementation but don't know how to implement it in Kotlin.</p>
  </blockquote>
  <pre><code>package com.main;
  
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.Map;
  
  import org.json.simple.JSONArray;
  import org.json.simple.JSONObject;
  import org.json.simple.parser.JSONParser;
  import org.json.simple.parser.ParseException;
  
  import com.google.common.collect.MapDifference;
  import com.google.common.collect.Maps;
  
  
  public class TestJson {
  
      public static void main(String[] args) {
          
          try {
              JSONParser parser = new JSONParser();
              
              Object obj1 = parser.parse(new FileReader(&quot;D:/test1.json&quot;));
              //Object obj2 = parser.parse(new FileReader(&quot;D:/test2.json&quot;));
              
              JSONArray jsonSites1 = (JSONArray)  obj1;
              //JSONArray jsonSites2 = (JSONArray)  obj2;
              JSONObject leftMap = (JSONObject) jsonSites1.get(0);
              //JSONObject leftMap = (JSONObject) parser.parse(new FileReader(&quot;D:/test3.json&quot;));
              
              JSONObject rightMap = (JSONObject) parser.parse(new FileReader(&quot;D:/test2.json&quot;));
              
             
              Map&lt;String, Object&gt; leftFlatMap = FlatMapUtil.flatten(leftMap);
              Map&lt;String, Object&gt; rightFlatMap = FlatMapUtil.flatten(rightMap);
              MapDifference&lt;String, Object&gt; difference = Maps.difference(leftFlatMap, rightFlatMap);
              
              System.out.println(&quot;Entries only on left\n--------------------------&quot;);
              difference.entriesOnlyOnLeft().forEach((key, value) -&gt; System.out.println(key + &quot;: &quot; + value));
              
              System.out.println(&quot;\n\nEntries only on right\n--------------------------&quot;);
              difference.entriesOnlyOnRight().forEach((key, value) -&gt; System.out.println(key + &quot;: &quot; + value));
  
              System.out.println(&quot;\n\nEntries differing\n--------------------------&quot;);
              difference.entriesDiffering().forEach((key, value) -&gt; System.out.println(key + &quot;: &quot; + value));
  
              System.out.println(&quot;\n\nEntries in common\n--------------------------&quot;);
              difference.entriesInCommon().forEach((key, value) -&gt; System.out.println(key + &quot;: &quot; + value));
  
              
              
              
          }catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (ParseException e) {
              e.printStackTrace();
          }
  
      }
  
  }
  //String json = leftMap.toJSONString();
  //String birthday = (String) data.get(&quot;birthday&quot;);
  //System.out.println(json);
  //System.out.println(birthday);
  </code></pre>