镜之Json Compare Diff | 技术创作特训营第一期 前言 “镜” 寓意是凡事都有两面性,Json对比也不例外! 因公司业务功能当中有一个履历的功能,它有多个版本的JSON数据需要对比出每个版本的不同差异节点并且将差异放置在一个新的JSON当中原有结构不能变动,差异节点使用数组对象的形式存储,前端点击标红即可显示多个版...
\n" +"}";try {// 将json转Json节点树JsonNode node1 = mapper.readTree(s1);JsonNode node2 = mapper.readTree(s2);List<String> ignoreKey = new ArrayList<>();// 获取两个JSON之间的差异Map<String, Object> nodesDiff = getNodesDiff(node1, node2,"", ignoreKey);System.out.println(mapper.wr...
JSON Diff is a free and open-source tool to compare two JSON objects and find differences. Visualize changes in JSON files, easy and fast.
* * @param json 要应用差异的原始 JSON 字符串 * @param diff 差异内容,即 {@link #getNodesDiff} 返回的 Map 对象 * @return 经过差异处理后的 JSON 字符串 */ public static String applyDiff(String json, Map<String, Object> diff) throws IOException { JsonNode node = mapper.readTree(json); ...
镜之Json Compare Diff 前言 “镜” 寓意是凡事都有两面性,Json对比也不例外! 因公司业务功能当中有一个履历的功能,它有多个版本的JSON数据需要对比出每个版本的不同差异节点并且将差异放置在一个新的JSON当中原有结构不能变动,差异节点使用数组对象的形式存储,前端点击标红即可显示多个版本的节点差异数据如下图...
childNode1,diff,"delete");}}for(Iterator<String>it=node2.fieldNames();it.hasNext();){StringfieldName=it.next();if(ignoreKey.contains(fieldName)){continue;}// 如果旧的没有这个数据那么表示新增if(node1.get(fieldName)==null){addToMap(path+fieldName,null,node2.get(fieldName),diff,"add")...
JsonCompareResult jsonCompareResult = new DefaultJsonDifference() .option(jsonComparedOption) .detectDiff(array1, array2); System.out.println(JSON.toJSONString(jsonCompareResult)); } } 主要分为两个对象 JsonComparedOption.class 和 JsonCompareResult.class;分别是配置对象和处理对象。
*@paramdifferences 差异字段*/privatestaticvoidcompareJsonNodes(JsonNode node1, JsonNode node2, Map<String, String>differences) { Iterator<String> fieldNames =node1.fieldNames();while(fieldNames.hasNext()) { String fieldName=fieldNames.next(); ...
class { public void diffKeepOrder() { String array1 = "[1, 2, 3, 4, 5]"; String array2 = "[1, 6, 3, 4, 5]"; // 构建配置对象 JsonComparedOption jsonComparedOption = new JsonComparedOption().setIgnoreOrder(true); // 初始化工具 JsonCompareResult jsonCompareResult = new Default...
This tool allows to compare two JSON online, and visualize the diff. How to compare two JSON ? Copy and paste, drag and drop a JSON file or directly type in the editors above, and they will be automatically compared if the two JSON are valids. You can also click on "load JSON...