JSON Diff Full Guide: Format and compare, and find real field differences
When the combination "Boths look almost as good as they look" or when the configuration center export "Only Indent" to a local file, or when the grey environment responds with an extra embedded field, it is slow and easily missed by JSON. This guidance describes the use of the structure level Diff, why it must be formatted, commonly misreported and operable, directly docking in KiloCell JSON Comparison。
The core sentence.
The first step is to become a legitimate and readable JSON, and then a "value on the path" Do not use two lines of compressed text as a string hard comparison.
A blank, key sequence, meaningless transposition causes text diff full of noise, but no semantics for the program. The structure is concerned with whether a path is new, deleted or changed. The following is the "System of the Step of Misreporting of the scenes and the Selection of the Sites":
What are you comparing?
JSON Diff has at least two meanings, and mixing would waste time.
| Level | Compare Object | Typical noise. | Fit |
|---|---|---|---|
| Text diff | Character/Line | Indent, line breaks, key sequences, spaces | Look at the format style, the plain text in the submission. |
| Structure diff | The tree and path after the resolution | Usually ignores pure blanks | Interface fields, configurations, business semantics |
| Semantic/Serval Diff | Sorting keys, regulation numbers, etc. | Whether the reliance rule is stated | Contract test, snapshot test |
Thousands of grids JSON Comparison Daily connection: each of them will be marked with a JSON, deciphered added / removed / changed(pages are colour-coded to distinguish new, deleted, changed). It answers "what's different with the data" and not "who's better indented."
Relationship to Git diff: Git defaults on JSON files to text diff. Git shows large changes when the key is reset or reformatted in its entirety, while the structure Diff may have only one or two fields. When reviewing configuration or API sample, structure Diff is then determined whether to fix the gap.
2. Why "format first and then compare"
Three independents are often rubbed in a paste:
- Legitimacy: Illegal JSON cannot access reliable structural comparisons.
- Readability: People need to be able to light the path to see the context.
- Comparability: Both sides should be first deconstructable; Reunification should be done when needed.
Recommended waterline:
Original text → Format/Validate →(Optional)KeysSortorNormative化 → Diff → Break读Path
Available in Compatibility 「Format」 When you click the button, you can order it first. "Start comparison."; If a side grammatical error, you should first arrive. JSON Format Fix it to parse, and then back to Diff. Formatting is particularly critical for a response that has been compressed into a row, otherwise it is difficult for you to match "change" to the business field name.
And then you'll compress it? Not normally. The compression changes the void, the structure Diff should not have relied on the blank.JSON Minify The volume that you want to transfer is not a Diff prefix. The first step in harmonizing the text is to consider the question of "tools misusing the blank as content" or to compare it to a purely text-level.
3. Operational steps (to tools)
- Open JSON Comparison。
- Paste "baseline " or " old version " on the left (e.g., previous environment response, examples in document, pre-merger configuration).
- The following is a list of the most recent posts on the website of the Global Voices website:
- Both sides come from the compression interface, click. 「Format」(
formatBoth) , confirmation can be carried out. - Click "Start comparison."。
- Read in the result area by legend:
- Added: Right side with no path left
- Delete(removed): Left, right, no
- Changed: Different from the path border
- Use when exchanging benchmarks "Sharing position.", avoid repainting.
- Available Load Example (b) Acquaintance with colour and path displays; Official data use 「Clear」 Prevent the string.
The habit of reading results.
- Look first. Number: One field changed or the whole tree was changed.
- Look again. Path prefix:
data.userLarge area changes are often the overall replacement of embedded objects rather than the ten unrelated fields. - The following is a logarithmic logarithmic: Note whether to achieve "indexing" or "do your best to match" The disordered sequence of the same arrays would be reflected in large changes - see the next section.
- For type change:
null→0、1→"1"It should be seen as a change, even if the business "looks useful".
Failure: If the tip cannot be deciphered, the entire side of the report is copied to the formatting tool and the illegal comma/quota is compared. Do not interpret Diff results on half JSON.
4. Where did the misreporting and underreporting come from?
| phenomena | Reason | Processing |
|---|---|---|
| Full of screens, but same business. | Consider as content in text, or in key order/space | With structure Diff; Format first |
| The array "all changed." | By location, the order of the elements has changed. | Confirming business interest in sequencing; Sort id before comparing if necessary |
| No discrepancies reported, but on the line, bug. | Compared to the wrong environment or the same. | Checking for the right and left sources; Exchange/clean reset |
| The tip of the float is different. | Sequencing precision, language differences | Business level agreed round or string amount |
| Time fields are always different | Generate a new time stamp for each request | Erase or mask variable fields before comparison |
| The illegal side still has "results." | Not a real parse | Formatting check is the rule. |
| Unicode is different | \u4e2d The same size as Han. |
Structure equals ignore text writing |
| The end of the big integer is different. | JS Precision | id When String |
| Only key case is different | Path case sensitive | You're using the real solver rule. Don't assume it's insensitive. |
Intentional comparison:
Left:
{"user":{"id":"1001","roles":["a","b"]},"ok":true}
Right:
{"ok":true,"user":{"id":"1001","roles":["a","b","c"]}}
It's different. It's a lot of things. roles[2]。 Diff should report to the main office. add roles associated, instead of deleting the whole object and adding it. If you see "rewrite the whole document", it means that you are comparing the text with inappropriate text.
5. Real scene
Scenario A: Back-to-back connection "not match field"
The front side says missing fields, and the back side says "reactions are in." Paste the actual JSON in the browser Network and the interface document examples to the left, Diff once. Common conclusion: Fields are embedded (in a nest)data.profile.avatar vs top floor avatar, or the document is expired. And then we'll take the pre-production and the production, and we'll exclude the environmental configuration drift.
scene B: Configure Center vs Local Files
JSON from the configuration center and the repository config.json Compare. Format first. If only the key is sorted differently, the structure Diff should be close to empty; If you have a switch, change the number of milliseconds over the time limit, then you can decide whether to publish it. Pre-sensitive values compared to mask.
Scenario C: "Compatibility check" for re-engineering interfaces
The old version and the new version of API fight the same request once each time. Expectations: Business fields are compatible and new fields are allowed. Diff should be primarily adeded and should not be heavily removed/changed. If the core field type changes from a digital string, even UI "shows" is entered in the breaking change.
Scenario D: YAML Equivalent Check After Reconfiguration
Use JSON ↔ YAML Move the changes to YAML to JSON, Diff. This will avoid the YAML text noise caused by pure indentation and focus on data. Note the type of pit that converts itself (see the JSON-YAML guide), and the type changes reported by Diff sometimes come from conversion rather than from your business submission.
6. Checklist
- [ ] Clear source indication (environment, time, request ID)
- [ ] Both sides are legal, JSON.
- [ ] Formatted and then compared
- [ ] Known variable fields (time stamp, request id, signature) removed or ignored
- [ ] Whether the array allows for a business conclusion
- [ ] Large integers/values have been processed in accordance with string policy
- [ ] The conclusion is that the path level changes, not the "different side" sentence.
- [ ] Empty pages with privacy-related responses
8. Common problems
Why is Diff less after formatting?
If you had been using text comparisons, formatting would have changed lines and so the difference "looks" would have become more or less different, and the result would have been unstable. Diff should be primarily data-sensitive in legal terms. If the formatted structure Diff results change, it indicates that at least one side of the format was not properly analyzed or that you were not looking at the same tool result.
Is it different if the key order is different?
For the vast majority of JSON objects, the default key sequence is regulated, and the application is also accessed by a keyname. Structure Diff usually treats objects in an equal order. If you are ludicrously reliant on the key sequence, it is a downstream problem, which should be shown separately in the document, rather than asking all Diff tools to warn in text order.
Why is the sequence red?
Indexed alignment is commonly achieved.[a,b] and [b,a] The location 0 and 1 will be shown. If the elements are stable, id, sort and paste the comparator first, or only extract the id set. Do not assume that all Diffs automatically compare the semantics with the arrays.
Can you drag two files into Git instead of this tool?
Text can be read, but noise is high when you reorder, type, line and row. Structure tools are more appropriate for API and configuration syntax. The two complement each other: the structure for issuing the review, Diff, and the history of the warehouse, Git.
Can the results be an automated assertion?
Pages are suitable for quick manual confirmation. The regression test should compare the same structure with CI (compact tests, snapshots). The manual Diff findings are deposited into the "list of paths allowed to add and/ or forbid changes" and are much more valuable than a single screenshot.
Next steps
- Open JSON Diff, dot "load examples" familiar with legends.
- The same JSON post was posted on each other to confirm the "no difference" baseline.
- Change only one embedded field on the right to an array of elements, then compare and practice reading paths.
- Next time you connect to a real response from Network, format it and Diff, and write the path to the bug list.