Semantic comparison
A text comparison of two JSON files reports every line that differs, even if the data is the same. A semantic comparison reads the JSON and compares the data. Key order never matters, and the options below let you decide what else should be ignored. The example is set up with an id match and an ignored updatedAt key, so you can see how they work.
The options
- Ignore array order: two arrays with the same items in a different order are equal. Use it for tags, permissions and other sets. Duplicates still count, so [1, 1, 2] is different from [1, 2].
- Ignore letter case: "Yes" and "yes" are the same text.
- Trim spaces: text with extra spaces at the ends is the same as the trimmed text.
- Ignore keys: a list of key names, such as updatedAt, requestId, separated by commas. These keys are left out at every depth. You can also give a full path, such as $.meta.generatedAt, to ignore one place only.
- Match array items by key: for arrays of objects such as users or products, enter the key that identifies each item, for example id. Items are then paired by that value, not by position, so a new item at the top of the list does not make every other item look changed. The differences are reported as $.users[id=3].name.
When to use each
| Situation | Option |
|---|---|
| An API returns a list in a different order | Match by key, or ignore array order |
| Responses carry timestamps or request ids | Ignore keys |
| Values differ only in capital letters | Ignore letter case |
| You want to see a change in the position of items | Leave the options off |
What is not ignored
A value that changes type, such as 1 becoming "1", is a difference, as is null against a missing key. The number 1 and the number 1.0 are the same, because JSON does not tell them apart. JavaScript keeps numbers with about 15 digits of precision, so a number larger than that is rounded before it is compared, and the tool warns you if it sees one.
For the basics, see JSON diff. To read the result as a full side by side view, use the JSON diff viewer, and see the guide for more on how comparison works.