@@ -67,6 +67,7 @@ Features Features::all() { return {}; }
6767Features Features::strictMode () {
6868 Features features;
6969 features.allowComments_ = false ;
70+ features.allowTrailingCommas_ = false ;
7071 features.strictRoot_ = true ;
7172 features.allowDroppedNullPlaceholders_ = false ;
7273 features.allowNumericKeys_ = false ;
@@ -454,7 +455,7 @@ bool Reader::readObject(Token& token) {
454455 initialTokenOk = readToken (tokenName);
455456 if (!initialTokenOk)
456457 break ;
457- if (tokenName.type_ == tokenObjectEnd && name.empty ()) // empty object
458+ if (tokenName.type_ == tokenObjectEnd && ( name.empty () || features_. allowTrailingCommas_ )) // empty object or trailing comma
458459 return true ;
459460 name.clear ();
460461 if (tokenName.type_ == tokenString) {
@@ -863,6 +864,7 @@ class OurFeatures {
863864public:
864865 static OurFeatures all ();
865866 bool allowComments_;
867+ bool allowTrailingCommas_;
866868 bool strictRoot_;
867869 bool allowDroppedNullPlaceholders_;
868870 bool allowNumericKeys_;
@@ -1437,7 +1439,7 @@ bool OurReader::readObject(Token& token) {
14371439 initialTokenOk = readToken (tokenName);
14381440 if (!initialTokenOk)
14391441 break ;
1440- if (tokenName.type_ == tokenObjectEnd && name.empty ()) // empty object
1442+ if (tokenName.type_ == tokenObjectEnd && ( name.empty () || features_. allowTrailingCommas_ )) // empty object or trailing comma
14411443 return true ;
14421444 name.clear ();
14431445 if (tokenName.type_ == tokenString) {
@@ -1866,6 +1868,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
18661868 bool collectComments = settings_[" collectComments" ].asBool ();
18671869 OurFeatures features = OurFeatures::all ();
18681870 features.allowComments_ = settings_[" allowComments" ].asBool ();
1871+ features.allowTrailingCommas_ = settings_[" allowTrailingCommas" ].asBool ();
18691872 features.strictRoot_ = settings_[" strictRoot" ].asBool ();
18701873 features.allowDroppedNullPlaceholders_ =
18711874 settings_[" allowDroppedNullPlaceholders" ].asBool ();
@@ -1884,6 +1887,7 @@ static void getValidReaderKeys(std::set<String>* valid_keys) {
18841887 valid_keys->clear ();
18851888 valid_keys->insert (" collectComments" );
18861889 valid_keys->insert (" allowComments" );
1890+ valid_keys->insert (" allowTrailingCommas" );
18871891 valid_keys->insert (" strictRoot" );
18881892 valid_keys->insert (" allowDroppedNullPlaceholders" );
18891893 valid_keys->insert (" allowNumericKeys" );
@@ -1917,6 +1921,7 @@ Value& CharReaderBuilder::operator[](const String& key) {
19171921void CharReaderBuilder::strictMode (Json::Value* settings) {
19181922 // ! [CharReaderBuilderStrictMode]
19191923 (*settings)[" allowComments" ] = false ;
1924+ (*settings)[" allowTrailingCommas" ] = false ;
19201925 (*settings)[" strictRoot" ] = true ;
19211926 (*settings)[" allowDroppedNullPlaceholders" ] = false ;
19221927 (*settings)[" allowNumericKeys" ] = false ;
@@ -1932,6 +1937,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
19321937 // ! [CharReaderBuilderDefaults]
19331938 (*settings)[" collectComments" ] = true ;
19341939 (*settings)[" allowComments" ] = true ;
1940+ (*settings)[" allowTrailingCommas" ] = true ;
19351941 (*settings)[" strictRoot" ] = false ;
19361942 (*settings)[" allowDroppedNullPlaceholders" ] = false ;
19371943 (*settings)[" allowNumericKeys" ] = false ;
0 commit comments