Skip to content

Parsing JSON with duplicate keys (json-cpp) #358

@ksl67

Description

@ksl67

I'm using JsonCpp v0.6.0 to parse the following JSON string:

{
   "3.7":"de305d54-75b4-431b-adb2-eb6b9e546011",
   "3.7":"de305d54-75b4-431b-adb2-eb6b9e546012",
   "3.8":"de305d54-75b4-431b-adb2-eb6b9e546013"
}

as follows:

    Json::Value  root;
    Json::Reader reader;

    // value contains the JSON string

    if (!reader.parse(value, root, false))
    {
        // parse error
    }

After the call to parse, root contains two entries in a map:

[0] first = "3.7", second = "de305d54-75b4-431b-adb2-eb6b9e546012",
[1] first = "3.8", second = "de305d54-75b4-431b-adb2-eb6b9e546013",

i.e. the first JSON record has been overwritten by the second. No errors are reported.

Is this behaviour expected? Is it correct?

I thought that an error might have been reported indicating that there is a duplicate key in the JSON string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions