Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we also compare the order of keys? #39

Open
sigmakappa opened this issue Jan 9, 2024 · 2 comments
Open

Can we also compare the order of keys? #39

sigmakappa opened this issue Jan 9, 2024 · 2 comments

Comments

@sigmakappa
Copy link
Contributor

Hi there!

Say as an example below:

expected = [
{'a': "1"},
{'b': "2"},
{'c': "3"},
{'d': "4"},
]
actual = [
{'a': "1"},
{'d': "4"},
{'b': "2"},
{'c': "3"},
]

Can JsonCompare be used to compare the order of keys? Expected has the order as abcd whereas actual has adbc.

Thanks in advance.

@rugleb
Copy link
Owner

rugleb commented Jan 10, 2024

Hi! No. I don't even know why this might be useful, because the order of keys in JSON objects shouldn't matter.

@sigmakappa
Copy link
Contributor Author

Hi again @rugleb . My bad for the bad example above. Consider the below example:

expected = [
{'Item': "A", 'price': "5.00"},
{'Item': "B", 'price': "4.50"},
{'Item': "C", 'price': "3.00"},
{'Item': "D", 'price': "2.75"},
]

Now if you observe the above JSON, the elements are sorted on descending order on the basis of the key 'price'.

Here, now can I compare the above with the below and can know if there is an issue in the order?

actual = [
{'Item': "A", 'price': "5.00"},
{'Item': "C", 'price': "3.00"},
{'Item': "D", 'price': "2.75"},
{'Item': "B", 'price': "4.50"}
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants