Giter VIP home page Giter VIP logo

json-diff's People

Contributors

deblockt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

json-diff's Issues

Ignore difference between null or empty array

Can be usefull to add a the possibility in LenientJsonArrayPartialMatcher to ignore difference between null array, array field not exist or empty array.
So this three example become the same

{
    name: "example"
    array : null
}
{
    name: "example"
    array : []
}
{
    name: "example"
}

NPE in PatchDiffViewer when comparing jsons containing empty json objects

Steps to reproduce

Run the Sample.java with

Test case 1
expected - {}
actual - {}

Test case 2
expected - { "a": {} }
actual - { "a": {} }

NPE will be thrown as below
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "diff" is null at com.deblock.jsondiff.viewer.PatchDiffViewer.toDiff(PatchDiffViewer.java:153) at com.deblock.jsondiff.viewer.PatchDiffViewer.toString(PatchDiffViewer.java:98) at java.base/java.lang.String.valueOf(String.java:4215) at java.base/java.io.PrintStream.println(PrintStream.java:1047) at com.deblock.jsondiff.Sample.main(Sample.java:34)

Diff not detected

            val org = """{"d":2}"""
            val new = """{"d":2, "e": {"f":"g"}}"""
            val matcher = CompositeJsonMatcher(
                LenientJsonArrayPartialMatcher(),
                LenientJsonObjectPartialMatcher(),
                StrictPrimitivePartialMatcher(),
            )
            val jsonDiff = DiffGenerator.diff(org, new, matcher)
            val patch = PatchDiffViewer.from(jsonDiff)

Neither the PatchDiffViewer nor the OnlyErrorDiffViewer detect any difference. I'm having a look to see if I can find the cause.

Similarity score NaN when comparing two exact similar jsons containing empty array

Steps to reproduce :

  • Use 0.0.8 version of the library.

  • Use

new LenientJsonArrayPartialMatcher(), // comparing array using lenient mode (ignore array order and extra items)
new LenientJsonObjectPartialMatcher(), // comparing object using lenient mode (ignoring extra properties)
new LenientNumberPrimitivePartialMatcher(new StrictPrimitivePartialMatcher()) // comparing primitive types and manage numbers (100.00 == 100)
);

Pass the below json for both expected and actual,

{ "a":[] }

Print the similarity score, expected 100, actual NaN

hard-coded 99.9 similarity causes issues

I'm using json-diff to diff quite large files, and need a variation of the OnlyErrorDiffViewer. Having a text node value change caused nothing in the OnlyErrorDiffViewer. The PatchDiffViewer however showed that the change was detected.

Some sleuthing showed that the hard-coded >= 99.9 in JsonObjectDiff:display is the culprit. Changing this to == 100.0 fixed my issue (my diff gave a similarityRate of 99.97).

I think the 99.9 is wrong. For this kind of work, it should just be a simple == 100.0. There's no need to be careful with floating point comparisons, because two json strings that represent the same floating point value will always have the same in-memory representation. Any change whatsoever will cause the result to become different from 100.

Thanks for the library, with the patch it's very useful for us at strmprivacy.io for tracking changes in large documents.

Indeterminism in json array comparison (LenientJsonArrayPartialMatcher), Results are differening based on array order

Hello, I recently discovered your JSON comparison implementation, and it appears to be the most suitable one for my specific use case among the open-source options I explored. While playing with some examples, I encountered this scenario,

The scenario,
expected
[ { "a": 1, "d": 5 }, { "a": 1, "b": 5 } ]

actual
[ { "a": 1, "d": 2 }, { "a": 1, "b": 3 } ]

The result is,
The property "$.0.d" didn't match. Expected 5, Received: 2
The property "$.1.b" didn't match. Expected 5, Received: 3

Same scenario when order of actual is changed,

expected : same as above
actual :
[ { "a": 1, "b": 3 }, { "a": 1, "d": 2 } ]

The result is
The property "$.0.d" in the expected json is not found
The property "$.1.b" in the expected json is not found

Dependancy on order of actual for the comparison seems undesirable to me. Thoughts?

[Feature request] Get the mismatched fields, missing fields as objects for custom usage

The OnlyErrorDiffViewer provides all the mismatch details between the expected and actual json as string in certain format. As a end user, i may want it in a different format than what's provided. Is it possible to expose a method that can fetch all the details displayed as an object so that it can be used as per our use case.

If something close to the below is returned it would be useful,
The mismatched errors could be a list of object, each object can have 3 string data members - path, expectedVal, actualVal
The not found in expected errors could be a list of string paths
The not found in actual errors could be a list of string paths

Add ci part to the project

We need to setup the ci part of the project to:

  • run unit test when pull request is created
  • create / publish the release

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.