Skip to content

Commit 527332d

Browse files
committed
add rejectDupKeys feature - not yet impld
1 parent cada3b9 commit 527332d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/json/reader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
320320
- `"failIfExtra": false or true`
321321
- If true, `parse()` returns false when extra non-whitespace trails
322322
the JSON value in the input string.
323+
- `"rejectDupKeys": false or true`
324+
- If true, `parse()` returns false when a key is duplicated within an object.
323325
324326
You can examine 'settings_` yourself
325327
to see the defaults. You can also write and read them just like any

src/lib_json/json_reader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ class OurFeatures {
916916
bool allowNumericKeys_;
917917
bool allowSingleQuotes_;
918918
bool failIfExtra_;
919+
bool rejectDupKeys_;
919920
int stackLimit_;
920921
}; // OurFeatures
921922

@@ -1896,6 +1897,7 @@ CharReader* CharReaderBuilder::newCharReader() const
18961897
features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool();
18971898
features.stackLimit_ = settings_["stackLimit"].asInt();
18981899
features.failIfExtra_ = settings_["failIfExtra"].asBool();
1900+
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
18991901
return new OurCharReader(collectComments, features);
19001902
}
19011903
static void getValidReaderKeys(std::set<std::string>* valid_keys)
@@ -1909,6 +1911,7 @@ static void getValidReaderKeys(std::set<std::string>* valid_keys)
19091911
valid_keys->insert("allowSingleQuotes");
19101912
valid_keys->insert("stackLimit");
19111913
valid_keys->insert("failIfExtra");
1914+
valid_keys->insert("rejectDupKeys");
19121915
}
19131916
bool CharReaderBuilder::validate(Json::Value* invalid) const
19141917
{
@@ -1941,6 +1944,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings)
19411944
(*settings)["allowNumericKeys"] = false;
19421945
(*settings)["allowSingleQuotes"] = false;
19431946
(*settings)["failIfExtra"] = true;
1947+
(*settings)["rejectDupKeys"] = true;
19441948
//! [CharReaderBuilderStrictMode]
19451949
}
19461950
// static
@@ -1955,6 +1959,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings)
19551959
(*settings)["allowSingleQuotes"] = false;
19561960
(*settings)["stackLimit"] = 1000;
19571961
(*settings)["failIfExtra"] = false;
1962+
(*settings)["rejectDupKeys"] = false;
19581963
//! [CharReaderBuilderDefaults]
19591964
}
19601965

0 commit comments

Comments
 (0)