Request for I-JSON (RFC 7493) Parsing Mode
I was wondering if there is any interest in implementing the I-JSON parsing mode for boost.json. I-JSON is an interoperable version of JSON which aims to remove some ambiguities in the parsing. The changes required for such a compliance are listed in Section 2 of the document.
It is very likely that we already follow these rules. If so, we should document it. If not, we should consider whether to follow it.
The only normative requirement we don't comply with is checking for duplicate object key. There is some normative encouragements in there that we don't strictly follow, such as limiting precision.
We never emit JSON with duplicates, as the DOM (via json::object) does not allow it. When we parse JSON, I believe we always take the first value if there are duplicate keys
The restriction of allowing only a single object key is during the parsing, not emission.
When an object is constructed during parsing, we check its elements for duplicates here: https://github.com/CPPAlliance/json/blob/ec29dfa768a16672534f758005dfe4841a8ea93d/include/boost/json/detail/impl/object_impl.ipp#L79 The duplicates are removed by replacing the duplicate with the last element in the object array, and then shrinking the array size by 1.
@vinniefalco To conform to I-JSON we would have the check for duplicate keys within basic_parser, not the handler.
Fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuck
basic_parser can never do such a thing, so I don't think we can claim I-JSON support for it. But that's okay, because we can claim I-JSON support in parser which is what 99% of users care about. For the other 1% of users who are implementing their own parser by using basic_parser directly, I think it is reasonable to expect that if they want I-JSON compliance, that can be responsible for it. How do you feel about that @jayeshbadwaik ?
One way to implement that in your codebase I see is to throw in case of duplicate in here: https://github.com/CPPAlliance/json/blob/ec29dfa768a16672534f758005dfe4841a8ea93d/include/boost/json/detail/impl/object_impl.ipp#L79
And handle that exception upward to report that the provided I-JSON document is ill-formed. This will require adding an option to parse_options to allow the user to parse in "I-JSON" mode and require you to remove noexcept qualifer for object_impl.build(). Since I am not aware of how the rest of the code works, I wonder if that is palatable.
Actually, when we detect a duplicate we can set a bit somewhere in the object and then in parser we can query new objects to see if there's a duplicate and throw as needed.
That can work too, yeah.
We should target this for the middle of year release?