Best way to compare 2 JSON files in Java

后端 未结 10 653
囚心锁ツ
囚心锁ツ 2020-12-13 13:56

How would you suggest this task is approached?

The challenge as i see it is in presenting diff information intelligently. Before i go reinventing the wheel, is there

10条回答
  •  遥遥无期
    2020-12-13 14:14

    The easiest way to compare json strings is using JSONCompare from JSONAssert library. The advantage is, it's not limited to structure only and can compare values if you wish:

    JSONCompareResult result = 
         JSONCompare.compareJSON(json1, json2, JSONCompareMode.STRICT);
    System.out.println(result.toString());
    

    which will output something like:

    Expected: VALUE1
         got: VALUE2
     ; field1.field2
    

提交回复
热议问题