Developer notes
Repair, compare and patch JSON with a preview.
Review JSON repairs, compare values instead of whitespace, and generate or apply all six JSON Patch operations locally.
By KeepSimp 4 min read
Fixing a comma and changing a value are different decisions. KeepSimp keeps those decisions visible: repair proposes valid JSON, comparison explains value changes, and a patch previews the resulting document before you replace anything.
Treat repair as a proposal.
In Edit, open More transformations and choose Preview repair. It can handle common pasted-text problems such as single quotes, unquoted property names, comments and trailing commas. The repair library may insert or remove content when it guesses your intent. Always inspect the result; a valid document can still contain the wrong data.
Format JSON validates strict JSON and preserves its tokens. Repair is a separate action, and your original text stays intact. Use result as source accepts the proposed result explicitly; Undo edit restores the previous source. Keep a separate original when a change matters.
{name:'Ada', active:true,}Compare JSON values, then check the direction.
Paste the original in Your JSON and the proposed version in Comparison JSON. Compare JSON shows additions, removals and replacements with JSON Pointer paths. Object property order and whitespace do not count as changes; arrays compare by position. Numbers compare as exact decimals, so 1 and 1.0 are equal while adjacent large integers remain different.
The generated patch transforms the source into the comparison document. Download JSON saves that patch. Swap documents reverses the direction. The comparison supports up to 500 changes; use Query to compare a smaller section if a large response exceeds the limit. Duplicate keys must be resolved first.
Preview all six patch operations.
JSON Patch is an array of operations defined by RFC 6902. KeepSimp supports add, remove, replace, move, copy and test. Use /items/- to append to an array, and escape property names with the JSON Pointer rules. test can confirm an expected old value before a later change proceeds.
Paste a patch into JSON Patch operations and select Preview patch. A failed operation rejects the whole preview and leaves your source unchanged. Removing the root is rejected because it would leave no JSON document; replace it with null if that is your intended result. Intermediate results are checked against the document limits so repeated copy operations cannot grow without a bound.
[
{"op":"test","path":"/name","value":"Ada"},
{"op":"replace","path":"/name","value":"Grace"}
]Further reading
Topics: repair JSON · fix invalid JSON · JSON diff · compare JSON · JSON Patch
A little less theory. A little more doing.
Try it on your own terms, with a free browser tool.
Try the tool