Comments (8)
Your scenario seems reasonable; maybe we can add an option to let differ respect the key order:
interface DifferOptions {
/**
* If the value is set, differ will make sure the key order of results is the same as inputs ("before" or "after").
* Otherwise, differ will sort the keys of results.
*/
preserveKeyOrder?: 'before' | 'after';
}
from json-diff-kit.
It's because of a bug that I forgot to change the compare operator to the cmp
result. It should be okay now.
from json-diff-kit.
lineNumber
field also did not respect the key order.
from json-diff-kit.
The key order does not affect JSON value, the following two JSONs should be assumed equal:
{ "a": 1, "z": 2 }
{ "z": 2, "a": 1 }
I think the behaviour of json-diff-kit is acceptable. Also, the algorithm relies on this behaviour - it scans keys on both sides from small to large (based on ASCII value).
If we should respect the key order (on which side?), we would not be able to display the "modified" lines (the yellow lines).
{ | {
"a": 1, | "z": 2,
"z": 2 | "a": 1
} | }
from json-diff-kit.
Thank you for your reply!
You are right, but I think at least a field (say "lineIndex" for example) should be provided to indicate all lines' original position, users will not like to see their json object being re-ordered, for example, user wouldn't like to see
{
"start_date": "20201231",
"end_date": "20210101"
}
turns into
{
"end_date": "20210101",
"start_date": "20201231"
}
from json-diff-kit.
Supported from 1.0.20
; playground is also updated.
from json-diff-kit.
Thank you for your work! We will try it out tomorrow on our project.
from json-diff-kit.
Wrong result of this example when using preserveKeyOrder: "after"
.
from json-diff-kit.
Related Issues (20)
- Performance issue when large jsons are diff HOT 3
- SyntaxError: Cannot use import statement outside a module HOT 4
- Comparing a non object with a object produces a non beautified object. HOT 1
- Add "ignoreCaseForKey" for Differ HOT 1
- Sytax highligting with prism HOT 2
- Type Error : Object is being assigned to a read-only property HOT 1
- Possible configuration for changing the highlighter color in Viewer HOT 1
- Comparing array from the end in some cases HOT 2
- Null problem HOT 2
- Comparing array with the same array with added object produces a non beautified object HOT 3
- `undefined` results in error HOT 6
- 'Show lines before' button is not working properly when there is no difference HOT 2
- When json contains more than the maximum integer allowed by js, precision is lost HOT 2
- Output html HOT 6
- Plans to split into packages?
- Request for Vue HOT 4
- With large JSON data, the buttons "Show line after/before" not working HOT 2
- Error `Unexpected token 'export'` when using with Remix/Vite
- JSON Patch format RFC 6902 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-diff-kit.