@@ -66,6 +66,7 @@ Features Features::all() { return {}; }
66
66
Features Features::strictMode () {
67
67
Features features;
68
68
features.allowComments_ = false ;
69
+ features.allowTrailingCommas_ = false ;
69
70
features.strictRoot_ = true ;
70
71
features.allowDroppedNullPlaceholders_ = false ;
71
72
features.allowNumericKeys_ = false ;
@@ -453,7 +454,7 @@ bool Reader::readObject(Token& token) {
453
454
initialTokenOk = readToken (tokenName);
454
455
if (!initialTokenOk)
455
456
break ;
456
- if (tokenName.type_ == tokenObjectEnd && name.empty ()) // empty object
457
+ if (tokenName.type_ == tokenObjectEnd && ( name.empty () || features_. allowTrailingCommas_ )) // empty object or trailing comma
457
458
return true ;
458
459
name.clear ();
459
460
if (tokenName.type_ == tokenString) {
@@ -862,6 +863,7 @@ class OurFeatures {
862
863
public:
863
864
static OurFeatures all ();
864
865
bool allowComments_;
866
+ bool allowTrailingCommas_;
865
867
bool strictRoot_;
866
868
bool allowDroppedNullPlaceholders_;
867
869
bool allowNumericKeys_;
@@ -1421,7 +1423,7 @@ bool OurReader::readObject(Token& token) {
1421
1423
initialTokenOk = readToken (tokenName);
1422
1424
if (!initialTokenOk)
1423
1425
break ;
1424
- if (tokenName.type_ == tokenObjectEnd && name.empty ()) // empty object
1426
+ if (tokenName.type_ == tokenObjectEnd && ( name.empty () || features_. allowTrailingCommas_ )) // empty object or trailing comma
1425
1427
return true ;
1426
1428
name.clear ();
1427
1429
if (tokenName.type_ == tokenString) {
@@ -1881,6 +1883,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
1881
1883
bool collectComments = settings_[" collectComments" ].asBool ();
1882
1884
OurFeatures features = OurFeatures::all ();
1883
1885
features.allowComments_ = settings_[" allowComments" ].asBool ();
1886
+ features.allowTrailingCommas_ = settings_[" allowTrailingCommas" ].asBool ();
1884
1887
features.strictRoot_ = settings_[" strictRoot" ].asBool ();
1885
1888
features.allowDroppedNullPlaceholders_ =
1886
1889
settings_[" allowDroppedNullPlaceholders" ].asBool ();
@@ -1899,6 +1902,7 @@ static void getValidReaderKeys(std::set<String>* valid_keys) {
1899
1902
valid_keys->clear ();
1900
1903
valid_keys->insert (" collectComments" );
1901
1904
valid_keys->insert (" allowComments" );
1905
+ valid_keys->insert (" allowTrailingCommas" );
1902
1906
valid_keys->insert (" strictRoot" );
1903
1907
valid_keys->insert (" allowDroppedNullPlaceholders" );
1904
1908
valid_keys->insert (" allowNumericKeys" );
@@ -1932,6 +1936,7 @@ Value& CharReaderBuilder::operator[](const String& key) {
1932
1936
void CharReaderBuilder::strictMode (Json::Value* settings) {
1933
1937
// ! [CharReaderBuilderStrictMode]
1934
1938
(*settings)[" allowComments" ] = false ;
1939
+ (*settings)[" allowTrailingCommas" ] = false ;
1935
1940
(*settings)[" strictRoot" ] = true ;
1936
1941
(*settings)[" allowDroppedNullPlaceholders" ] = false ;
1937
1942
(*settings)[" allowNumericKeys" ] = false ;
@@ -1947,6 +1952,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
1947
1952
// ! [CharReaderBuilderDefaults]
1948
1953
(*settings)[" collectComments" ] = true ;
1949
1954
(*settings)[" allowComments" ] = true ;
1955
+ (*settings)[" allowTrailingCommas" ] = true ;
1950
1956
(*settings)[" strictRoot" ] = false ;
1951
1957
(*settings)[" allowDroppedNullPlaceholders" ] = false ;
1952
1958
(*settings)[" allowNumericKeys" ] = false ;
0 commit comments