You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the names within an object are not
unique, the behavior of software that receives such an object is
unpredictable. Many implementations report the last name/value pair
only. Other implementations report an error or fail to parse the
object, and some implementations report all of the name/value pairs,
including duplicates.
... and currently, the nlohmann::json library implements the 1st behavior only (i.e. only the last key/value pair is loaded in case of duplicated keys).
@nlohmann suggests that the 2nd behavior (i.e. reporting an error) could be implemented using parser callbacks. However:
reporting the location of the duplicates (line/column number in the JSON file) is not possible with the parser callback,
I believe that preferring to report an error than silently ignore some of the key/value pairs is a quite common use-case, especially when loading JSON files that need thorough validation (typically because of possible manual edition).
Then, would it be possible to implement the "raise error in case of duplicate keys" behavior as a builtin optional feature in the nlohmann::json library? (typically a behavior for which it could be possible to opt-in when invoking nlohmann::json::parse(..))
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I would like to re-open the discussion on how objects with non-unique should be handled at load. This topic has been discussed previously there:
As stated by @nlohmann, RFC 7159 states that:
... and currently, the nlohmann::json library implements the 1st behavior only (i.e. only the last key/value pair is loaded in case of duplicated keys).
@nlohmann suggests that the 2nd behavior (i.e. reporting an error) could be implemented using parser callbacks. However:
Then, would it be possible to implement the "raise error in case of duplicate keys" behavior as a builtin optional feature in the nlohmann::json library? (typically a behavior for which it could be possible to opt-in when invoking
nlohmann::json::parse(..))Beta Was this translation helpful? Give feedback.
All reactions