Suggestion to handle duplication key properties in object-level #4649
Omar-Medina
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear nLohmann-Json Team,
Thank you once again for providing the amazing library.
I'm currently using the SAX interface to detect if any key-property within an object-level is duplicated.
To clarify, the term "object level" does not include any existing sub-object levels. Here are some examples to illustrate:
Example of duplication:
{"a":"s","a":"c"} // Key-property "a" is duplicated.
Example without duplication:
{"a":"s","z":{"a":"c"}} // Key-property "a" is not duplicated.
I have noticed that some JSON schema validator libraries do not report a failure when a key within an object level is duplicated,
which conforms to the standard. However, in my case, I want to catch such failures in JSON configurations.
See please below used code snip below.
In addtion. It was neccesary to modify (quick and dirty) the nlohmann library, so that the following mesages are provided, when a duplication has veen found.
The modification consist of extension of the nlohmann::json::json_sax_t with a new function.
void position(nlohmann::detail::position_t position).
this allows to get the currently position of the Json-file during the parsing.
patch for nLohmann/json.hpp:
Demo Class
How to use:
Your library has been incredibly helpful, and I appreciate the hard work you put into it.
Omar
Beta Was this translation helpful? Give feedback.
All reactions