Skip to content

Should JSON Formatting Support JSON Objects With Non-String Keys? #2

@rtillery

Description

@rtillery

JSON is only meant to support objects with members consisting of a string and a value (see JSON|member on https://www.crockford.com/mckeeman.html). When representing C++ Standard Library containers with key/value elements, the JSON member string corresponds with the C++ container key. However, C++ containers can use other types as the key. The question is whether the JSON serialization format of fmtster should allow these other types to be used as keys, serializing them into the output in place of the string (presuming serialization of the types are supported when they are values), or an exception should be thrown when they are encountered.

If non-string keys are accepted and written into a JSON string output, the resulting JSON would be non-compliant.

If the exception is thrown for non-string keys, it is assumed that an additional serialization type that is an extended JSON-like type that does allow this to be added, since one of the goals of fmtster is to be able to serialize as many containers as possible, especially those that use only fundamental and C++ Standard Library types.

Or, perhaps there is a configuration setting that chooses whether these types of keys are allowed. Note that choosing this option still will require the choice of whether accepting non-string keys is the default setting or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions