GithubHelp home page GithubHelp logo

Comments (10)

zgrossbart avatar zgrossbart commented on August 16, 2024 1

That makes sense. Thank you @LucasAstol.

The problem here is that those JSON objects aren't semantically equal.

{
    "my array": [
        "one",
        "two"
    ]
}

isn't the same as

{
    "my array": [
        "two",
        "one"
    ]
}

You could sort the arrays and then do the compare, but that's not an isEqual function, that's specialized business logic.

A few people have taken this project and built NodeJS utilities out of it. You might want to check those out if you're looking for an API.

from jdd.

raqbit avatar raqbit commented on August 16, 2024

I'm currently working on parsing an API and json-stringifying it again to check if I parse everything correctly.

This API returns several arrays with non-semantic ordering which changes every request.

Adding the ability to ignore array ordering would make it a lot easier to debug 👍

from jdd.

zgrossbart avatar zgrossbart commented on August 16, 2024

Thank you @raqbit. I've been going back and forth about this. The problem is that arrays in JSON have a semantically significant ordering so they are different. I'm still working out the best way to handle this.

from jdd.

LucasAstol avatar LucasAstol commented on August 16, 2024

Hi @zgrossbart

I really appreciate your tool, it helped me test large JSONs and also code a test for JSON comparisson in Postman. However I seem to have this same issue with your tool and with JS libraries, specially lodash when using _.isEqual method.

By your code I see you have written the functions yourself, so I hope you can solve this issue since it would be really helpful. I wouldn't be abe to copy your code due to my knowledge limitations but would be more than glad to use your tool for testing.

Another really cool thing would be to have an API that when sending two JSON objects one can obtain the comparisson results in a response :D

Keep up the good work

Best.

from jdd.

zgrossbart avatar zgrossbart commented on August 16, 2024

@LucasAstol, can you please give me some more information. I'm not sure what you're asking.

from jdd.

LucasAstol avatar LucasAstol commented on August 16, 2024

Sorry it was a bit messy.

Mainly I'd like to know if there's a chance that you have solved this particular issue on the array order as @vbro mentions.
I happen to have really large JSONs with arrays of objects that contain other arrays, and so on... Thus the json-diff fails event hough the JSON objects are semantically equal.

Moreover I'm proposing that it would be nice to have an API so we can directly send JSONs and get the validation results.

Best.

from jdd.

pochopsp avatar pochopsp commented on August 16, 2024

@zgrossbart Sorry to bring this up again after all this time, but I'd like to ask if something like that would actually be possible.
I am working on an access protocol based on OAuth2 which uses very complex json objects NOT considering order inside array, so for it ["a", "b"] is the same as ["b", "a"].

I love your tool and I use it a lot, but I would find it even more useful if it had an option to choose wether it should consider order in arrays.

As regards the web interface, it could just be a flag saying "Compare arrays ignoring order" which would be always disabled unless user wanted to use it.

from jdd.

zgrossbart avatar zgrossbart commented on August 16, 2024

@pochopsp, thanks for reaching out about this. If your JSON data has a set of values where the order doesn't matter then why are you using an array? The easiest way to implement this feature would be to sort the arrays before comparing them. The problem is that brings up a lot of issues.

For example: does

{
    "my array": [
        "one",
        "two"
    ]
}

equal

{
    "my array": [
        "one",
        "",
        "two"
    ]
}

What about

{
    "my array": [
        "one",
        null,
        "two"
    ]
}

A lot of these questions become unanswerable since you need to make specific decisions that aren't covered by the JSON specification.

If you have enough of a specific need for this then you could change the code locally to make this happen. I'd be happy to point you in the right direction.

from jdd.

pochopsp avatar pochopsp commented on August 16, 2024

Hi @zgrossbart . Thanks for your kind reply.
I'm using an array because the protocol specify it.
We only need a list of strings, no matter their order.

These are the specs: https://openid.net/specs/openid-connect-federation-1_0.html
See section 5.1.2 (metadata policy), there are a lot of examples of arrays in which order doesn't matter.

Like this one:
image
That list only states which algorithms are supported, their order doesn't matter.

As regards your example, in my opinion the three versions of "my array" are all different between each other. As far as I'm concerned, I'd consider "" to be different than null, and both certainly have a different meaning than a missing value.

Still, you're right, the official JSON specifications don't cover these cases, so it's legit to think that it would be too messy/ambiguous to implement this feature.

from jdd.

zgrossbart avatar zgrossbart commented on August 16, 2024

Thank you for understanding @pochopsp. If you have a one-time need I'm happy to point you to how to change the code to do that.

from jdd.

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.