json
json copied to clipboard
Support for integer keys in the SAX interface when parsing CBOR
Currently parsing CBOR with this library can only handle string keys. At the project I am working on, we want to use integer keys to reduce the size of our responses by using them as an alias for the long string keys. As such it would be very helpful to have some way to transform those to integer keys. While this would probably not fit into the STL-like interface, there is place to add it to the SAX interface.
My proposal would be to add overloads for bool key(string_t& val);
, which take an integer or similar types. The default version of those functions should still emit a parse error, but a library user would be able to override them and decide how to handle them differently. That way I can transform the CBOR into something, that can be handled via the STL interface (or one could even use that to build some native structs).
One issue I see with that, is how to handle the default implementation, which should call bool parse_error(std::size_t position, const std::string& last_token, const detail::exception& ex);
imo. This has more parameters, which may have gotten lost already? This may be solveable by accessing some internal state, but I am not familiar enough with the library to be able to tell, if this is actually doable.
Alternatives
One could probably also implement the parsing in the parse_error
callback, but that would be difficult and error prone. Maybe there is also already a way to do this already, but I don't know how.
PS: How do I tag this as enhancement?
Related: https://github.com/nlohmann/json/pull/2477
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Well, Mr. bot, I just didn't have time to work on that yet. I would like to have this feature at some point though, since it will be needed for low bandwidth support in my Matrix client. ;-)