Best way to compare 2 JSON files in Java

后端 未结 10 648
囚心锁ツ
囚心锁ツ 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:25

    I've done good experience with JSONAssert.

    import org.junit.Test;
    import org.apache.commons.io.FileUtils;
    import org.skyscreamer.jsonassert.JSONAssert;
    import org.skyscreamer.jsonassert.JSONCompareMode;
    
    ... 
    @Test
    public void myTest() {
      String expectedJson = FileUtils.readFileToString("/expectedFile");
      String actualJson = FileUtils.readFileToString("/actualFile");
      JSONAssert.assertEquals(expectedJson, actualJson, JSONCompareMode.STRICT);
    }
    ... 
    

提交回复
热议问题