Comments (10)
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.
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.
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.
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.
@LucasAstol, can you please give me some more information. I'm not sure what you're asking.
from jdd.
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.
@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.
@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.
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:
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.
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)
- Improve styling by using stronger colours and monospaced font HOT 1
- Add ghost placeholders for missing properties HOT 6
- Corrupts the global namespace, hard to inject multiple instances in page HOT 3
- enhancement:add panel customize my own color style HOT 1
- Update the copyright year HOT 3
- Query String Parameters HOT 2
- Issue with certain json data HOT 1
- Comparing very large JSON documents causes the browser to run out of memory. HOT 5
- THIS IS AMAZING HOT 1
- web app getting hanged for very large files HOT 4
- When running from Docker container, auto-loading of JSON does not work HOT 2
- Does not detect differences for very large integers HOT 4
- Maintain all object differences in same level HOT 4
- Doesn't understand insertion/deletion in the middle of a list HOT 1
- jsondiff.com broken by ezoic HOT 1
- Push Image to Dockerhub? HOT 4
- Removal of jQuery from jdd HOT 6
- Support data URLs HOT 9
- Collapse (hide) same lines HOT 4
- toogle filter should reduce the right navigation
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 jdd.