Menu

#22 Bug when parsing duplicate names

0.5.0
closed-accepted
nobody
Reader (16)
3
2015-03-06
2010-09-09
Sekhar
No

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"
}

Discussion

  • Sekhar

    Sekhar - 2010-09-09
    • milestone: --> 0.5.0
     
  • Christopher Dunn

    • priority: 5 --> 3
    • status: open --> open-accepted
     
  • Christopher Dunn

    Good point. Thanks, @Sekhar.

     
  • Christopher Dunn

    • status: open-accepted --> open
     
  • Gaurav

    Gaurav - 2014-11-10

    I think the above input json is valid as http://jsonlint.com/ also passes it.

     
  • Christopher Dunn

    Well, I guess strict-mode should match the RFC, no?

    (Note that the project has moved to GitHub.)

     
  • Christopher Dunn

    • status: open --> closed-accepted
     

Log in to post a comment.