Skip to main content

Data & Development

How to Compare JSON Text—and When You Need More

JSON is a text format for structured data. A regular text diff can highlight edits in a JSON file, but it does not parse the document or explain whether two JSON values mean the same thing.

A JSON text panel with two values and a magnifying lens
Table of Contents
  1. A quick JSON refresher
  2. Where JSON came from and where it appears
  3. Compare a JSON text revision
  4. Formatting changes versus value changes
  5. When a JSON-aware diff is necessary

A quick JSON refresher

JSON represents values using objects, arrays, strings, numbers, true, false, and null. Objects group named properties; arrays preserve an ordered sequence. The JSON specification defines these forms and their syntax. RFC 8259 (opens in a new tab) is the standard reference.

A JSON object with two properties
Example text
{"timeout":30,"mode":"safe"}

This is a single-line JSON text example. A character-level diff can compare it literally, but it does not validate the JSON or understand property paths.

Where JSON came from and where it appears

Douglas Crockford recounts that he independently recognized JavaScript object literals as a useful data-interchange format while working at State Software in April 2001, then published a page about JSON in 2002. JSON is still commonly used in web APIs: request and response bodies may use the application/json media type, though APIs can use other formats. Crockford’s account of JSON’s history (opens in a new tab) and the OpenAPI request-body specification (opens in a new tab) provide further context.

Compare a JSON text revision

A value changed in the text
Original
{"timeout":30,"mode":"safe"}
Modified
{"timeout":45,"mode":"safe"}

A text diff can highlight the characters that changed from 30 to 45. It will not report a structured path such as $.timeout or decide whether the new value is valid for your application.

For review, put the old document in Original and the revised document in Modified. Check that the text is complete and valid in your own JSON tooling, then inspect each highlighted change in context.

Formatting changes versus value changes

A text comparison works on characters and lines. Reformatting indentation can create many visible changes. Reordering properties in a JSON object can also change the text even when a parser treats the object’s members as unordered. Conversely, similar-looking text can be invalid JSON. Arrays are ordered, so changing array order can change the represented value.

Diff Checker’s Ignore Whitespace option changes how spaces and tabs are matched, but it does not switch the tool into JSON mode. The comparison still operates on text and does not validate syntax.

When a JSON-aware diff is necessary

  • You need a result by object path, such as which field changed.
  • You want formatting-only edits ignored while preserving JSON value semantics.
  • You need schema validation, array-specific matching, or a machine-readable change report.