Git Product home page Git Product logo

Comments (8)

RexSkz avatar RexSkz commented on September 19, 2024 1

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.

RexSkz avatar RexSkz commented on September 19, 2024 1

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.

Paper-Folding avatar Paper-Folding commented on September 19, 2024

lineNumber field also did not respect the key order.

from json-diff-kit.

RexSkz avatar RexSkz commented on September 19, 2024

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.

Paper-Folding avatar Paper-Folding commented on September 19, 2024

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.

RexSkz avatar RexSkz commented on September 19, 2024

Supported from 1.0.20; playground is also updated.

from json-diff-kit.

Paper-Folding avatar Paper-Folding commented on September 19, 2024

Thank you for your work! We will try it out tomorrow on our project.

from json-diff-kit.

Paper-Folding avatar Paper-Folding commented on September 19, 2024

Wrong result of this example when using preserveKeyOrder: "after" .

from json-diff-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.