Compare Java JSON Online

Paste two Java JSON objects (from Jackson or Gson). See what was added, removed, or changed — key by key.

🔒 100% private — runs entirely in your browser

or try sample data

What is Java JSON Diff?

Java JSON Diff compares two JSON objects — typically serialized with Jackson's ObjectMapper or Gson's toJson() — and shows you exactly which keys were added, removed, or modified. Unlike Java, which has no built-in JSON support, this tool gives you instant visual diffs without adding Maven/Gradle dependencies.

Java developers commonly use Jackson or Gson for JSON processing. Jackson's JsonNode.equals() and Gson's JsonElement.equals() check structural equality, but both return only a boolean. For detailed diffs, you'd typically reach for zjsonpatch (RFC 6902) or write custom comparators. This tool provides the same insight instantly in your browser.

Paste your JSON (e.g., Spring Boot configs, API request/response bodies, or serialized POJOs). The tool handles nested objects, arrays, nulls, and mixed types. Everything runs client-side — your data never leaves your machine.

Java JSON Comparison — Code Examples

Jackson readTree() with equals()

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = new ObjectMapper(); JsonNode node1 = mapper.readTree( "{\"name\": \"Alice\", \"age\": 30}"
);
JsonNode node2 = mapper.readTree( "{\"name\": \"Alice\", \"age\": 31}"
); System.out.println(node1.equals(node2)); // false // Iterate fields to find differences
Iterator<String> fields = node1.fieldNames();
while (fields.hasNext()) { String field = fields.next(); if (!node1.get(field).equals(node2.get(field))) { System.out.printf("%s: %s -> %s%n", field, node1.get(field), node2.get(field)); }
}
// age: 30 -> 31

Jackson's equals() is order-insensitive for objects but only returns a boolean. Field iteration works for flat structures.

Gson parseString() comparison

import com.google.gson.JsonElement;
import com.google.gson.JsonParser; JsonElement elem1 = JsonParser.parseString( "{\"host\": \"localhost\", \"port\": 3306}"
);
JsonElement elem2 = JsonParser.parseString( "{\"host\": \"db.prod\", \"port\": 5432}"
); System.out.println(elem1.equals(elem2)); // false // Compare as JsonObjects
var obj1 = elem1.getAsJsonObject();
var obj2 = elem2.getAsJsonObject();
for (String key : obj1.keySet()) { if (!obj1.get(key).equals(obj2.get(key))) { System.out.printf("%s changed%n", key); }
}

Gson's JsonElement.equals() compares structure and values. Like Jackson, it doesn't produce a detailed diff report.

zjsonpatch for RFC 6902 diffs

import com.flipkart.zjsonpatch.JsonDiff;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = new ObjectMapper();
JsonNode source = mapper.readTree("{\"a\": 1, \"b\": 2}");
JsonNode target = mapper.readTree("{\"a\": 1, \"c\": 3}"); JsonNode patch = JsonDiff.asJson(source, target);
System.out.println(patch.toPrettyString());
// [{"op": "remove", "path": "/b"},
// {"op": "add", "path": "/c", "value": 3}]

zjsonpatch produces RFC 6902 JSON Patch operations. Great for programmatic diffs — this online tool provides a visual alternative.

Java JSON Comparison Gotchas

Jackson vs Gson field ordering

Jackson and Gson may serialize object fields in different order. Jackson follows Java field declaration order by default; Gson sorts alphabetically. When comparing JSON from different libraries, always compare parsed structures (not strings) to avoid false diffs from ordering differences.

BigDecimal precision differences

Jackson can serialize BigDecimal(10.0) as 10.0 while Gson may produce 10. These represent the same value but produce different JSON strings. Use JsonNode.equals() (which handles numeric coercion) rather than string comparison. This tool compares parsed values, so 10 and 10.0 are treated as equal.

NullNode vs MissingNode

In Jackson, a key with value null produces a NullNode, while a missing key returns MissingNode. Both appear as "absent" in different ways, but {"key": null} and {} are semantically different. This tool correctly distinguishes between explicit null values and missing keys.

Frequently Asked Questions

How do I compare two Java JSON objects online?

Paste your JSON objects into the two panels and click Compare. The tool highlights added, removed, and modified keys with color-coded diffs.

Can I compare nested Jackson JsonNode objects?

Yes. The tool performs deep comparison of nested objects, arrays, and mixed structures at any depth. Nested changes are shown with path-based highlighting.

Should I use Jackson or Gson for JSON comparison?

Both work well. Jackson's JsonNode.equals() handles numeric type coercion (e.g., int vs double). Gson's JsonElement.equals() is strict about types. For visual comparison, paste JSON from either library into this tool.

Is my Java JSON data safe?

Yes. This tool runs entirely in your browser using client-side JavaScript. Your data is never sent to any server, making it safe for comparing Spring Boot configs or API payloads.

Can I compare Spring Boot application.yml as JSON?

Yes. Convert your YAML config to JSON format and paste it. The tool compares all nested properties structurally, which is great for comparing dev vs prod Spring configurations.

Does this handle Java's BigDecimal precision in JSON?

JSON numbers are compared as parsed values. 10 and 10.0 are treated as equal. However, if your serializer produces different precision (e.g., 10.00 vs 10), the raw JSON strings will differ before parsing.