As per RFC4627 (section 2.2), names within an object should be unique. When using JSONCPP's strict mode, parsing such an object should fail.
As of now, JSONCPP does not return an error:
Sample JSON (duplicate_key.json):
{
"Object": {
"Key":"Value",
"Key":"Value"}
}
Sample code to test the above file:
ifstream inFile("duplicate_key.json");
Json::Value root;
Json::Reader reader(Json::Features::strictMode());
if ( false==reader.parse( inFile, root, false ) )
{
cerr << "Error reading file " << reader.getFormatedErrorMessages() << endl;
}
cout << root["Object"] << endl;
Output:
{
"Key" : "Value"
}
Good point. Thanks, @Sekhar.
I think the above input json is valid as http://jsonlint.com/ also passes it.
Well, I guess strict-mode should match the RFC, no?
(Note that the project has moved to GitHub.)
Fixed at: https://github.com/open-source-parsers/jsoncpp/pull/205