Java tutorial
//package com.java2s; //License from project: Apache License import org.json.JSONException; import org.json.JSONObject; import java.util.Iterator; public class Main { public static JSONObject shallowDiffJSONObjects(JSONObject jo1, JSONObject jo2) throws JSONException { JSONObject result = new JSONObject(); Iterator<String> it = jo2.keys(); while (it.hasNext()) { String key = it.next(); // See if the key is missing or the value is different in the other object Object val1 = jo1.opt(key); Object val2 = jo2.get(key); if (val1 == null || !val2.equals(val1)) result.put(key, val2); } return result; } }