@@ -67,6 +67,7 @@ Features Features::all() { return {}; }
67
67
Features Features::strictMode () {
68
68
Features features;
69
69
features.allowComments_ = false ;
70
+ features.allowTrailingCommas_ = false ;
70
71
features.strictRoot_ = true ;
71
72
features.allowDroppedNullPlaceholders_ = false ;
72
73
features.allowNumericKeys_ = false ;
@@ -454,7 +455,7 @@ bool Reader::readObject(Token& token) {
454
455
initialTokenOk = readToken (tokenName);
455
456
if (!initialTokenOk)
456
457
break ;
457
- if (tokenName.type_ == tokenObjectEnd && name.empty ()) // empty object
458
+ if (tokenName.type_ == tokenObjectEnd && ( name.empty () || features_. allowTrailingCommas_ )) // empty object or trailing comma
458
459
return true ;
459
460
name.clear ();
460
461
if (tokenName.type_ == tokenString) {
@@ -863,6 +864,7 @@ class OurFeatures {
863
864
public:
864
865
static OurFeatures all ();
865
866
bool allowComments_;
867
+ bool allowTrailingCommas_;
866
868
bool strictRoot_;
867
869
bool allowDroppedNullPlaceholders_;
868
870
bool allowNumericKeys_;
@@ -1437,7 +1439,7 @@ bool OurReader::readObject(Token& token) {
1437
1439
initialTokenOk = readToken (tokenName);
1438
1440
if (!initialTokenOk)
1439
1441
break ;
1440
- if (tokenName.type_ == tokenObjectEnd && name.empty ()) // empty object
1442
+ if (tokenName.type_ == tokenObjectEnd && ( name.empty () || features_. allowTrailingCommas_ )) // empty object or trailing comma
1441
1443
return true ;
1442
1444
name.clear ();
1443
1445
if (tokenName.type_ == tokenString) {
@@ -1866,6 +1868,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
1866
1868
bool collectComments = settings_[" collectComments" ].asBool ();
1867
1869
OurFeatures features = OurFeatures::all ();
1868
1870
features.allowComments_ = settings_[" allowComments" ].asBool ();
1871
+ features.allowTrailingCommas_ = settings_[" allowTrailingCommas" ].asBool ();
1869
1872
features.strictRoot_ = settings_[" strictRoot" ].asBool ();
1870
1873
features.allowDroppedNullPlaceholders_ =
1871
1874
settings_[" allowDroppedNullPlaceholders" ].asBool ();
@@ -1884,6 +1887,7 @@ static void getValidReaderKeys(std::set<String>* valid_keys) {
1884
1887
valid_keys->clear ();
1885
1888
valid_keys->insert (" collectComments" );
1886
1889
valid_keys->insert (" allowComments" );
1890
+ valid_keys->insert (" allowTrailingCommas" );
1887
1891
valid_keys->insert (" strictRoot" );
1888
1892
valid_keys->insert (" allowDroppedNullPlaceholders" );
1889
1893
valid_keys->insert (" allowNumericKeys" );
@@ -1917,6 +1921,7 @@ Value& CharReaderBuilder::operator[](const String& key) {
1917
1921
void CharReaderBuilder::strictMode (Json::Value* settings) {
1918
1922
// ! [CharReaderBuilderStrictMode]
1919
1923
(*settings)[" allowComments" ] = false ;
1924
+ (*settings)[" allowTrailingCommas" ] = false ;
1920
1925
(*settings)[" strictRoot" ] = true ;
1921
1926
(*settings)[" allowDroppedNullPlaceholders" ] = false ;
1922
1927
(*settings)[" allowNumericKeys" ] = false ;
@@ -1932,6 +1937,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
1932
1937
// ! [CharReaderBuilderDefaults]
1933
1938
(*settings)[" collectComments" ] = true ;
1934
1939
(*settings)[" allowComments" ] = true ;
1940
+ (*settings)[" allowTrailingCommas" ] = true ;
1935
1941
(*settings)[" strictRoot" ] = false ;
1936
1942
(*settings)[" allowDroppedNullPlaceholders" ] = false ;
1937
1943
(*settings)[" allowNumericKeys" ] = false ;
0 commit comments