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

duplicate key #1095

Closed
ilyasamraoui opened this issue Sep 24, 2019 · 5 comments
Closed

duplicate key #1095

ilyasamraoui opened this issue Sep 24, 2019 · 5 comments
Labels
bug v6 ArduinoJson 6

Comments

@ilyasamraoui
Copy link

Hi,
DesrializationError validate json char array that has duplicate key

@bblanchon
Copy link
Owner

Hi @ilyasamraoui,

Indeed, the goal of ArduinoJson is to offer a lightweight parser for embedded platforms and not a JSON validator.
I don't think it's worth increasing the size of the code for such an edge case.

Do you have a use case where detecting duplicate keys is crucial?

Best Regards,
Benoit

@bblanchon
Copy link
Owner

I just made the test and the code grew by only 26 bytes; so that may be worth it.
But do we really need this?

@bblanchon
Copy link
Owner

Looking at this question on stackoverflow, I realized that duplicate keys are not illegal and are accepted by most implementations.

All major implementations keep the last value:

  • Chrome 77: JSON.parse('{"a":1,"a":2}') -> {a: 2}
  • IE 11: JSON.parse('{"a":1,"a":2}') -> {a: 2}
  • Edge 44: JSON.parse('{"a":1,"a":2}') -> {a: 2}
  • Firefox 68: JSON.parse('{"a":1,"a":2}') -> {a: 2}
  • Python 3.6.8: json.loads('{"a":1,"a":2}') -> {'a': 2}
  • Ruby: JSON.parse('{"a":1,"a":2}') -> {"a"=>2}

So deserializeJson() should return Ok, but the JsonDocument should contain the last value.

@bblanchon bblanchon added the bug label Sep 27, 2019
@ilyasamraoui
Copy link
Author

ok i see, i used jsonlint.com to validate json object with duplicate key and it didn't validate it

Repository owner locked and limited conversation to collaborators Oct 31, 2019
@bblanchon
Copy link
Owner

Fix published in ArduinoJson 6.13.0

@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants