forked from nlohmann/json
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nlohmann#25 from nlohmann/develop
Sync Fork from Upstream Repo
- Loading branch information
Showing
34 changed files
with
845 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
#include <nlohmann/json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
int main() | ||
{ | ||
// an invalid JSON text | ||
std::string text = R"( | ||
{ | ||
"key": "value without closing quotes | ||
} | ||
)"; | ||
|
||
// parse with exceptions | ||
try | ||
{ | ||
json j = json::parse(text); | ||
} | ||
catch (json::parse_error& e) | ||
{ | ||
std::cout << e.what() << std::endl; | ||
} | ||
|
||
// parse without exceptions | ||
json j = json::parse(text, nullptr, false); | ||
|
||
if (j.is_discarded()) | ||
{ | ||
std::cout << "the input is invalid JSON" << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "the input is valid JSON: " << j << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a target="_blank" href="https://wandbox.org/permlink/2TsG4VSg87HsRQC9"><b>online</b></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[json.exception.parse_error.101] parse error at line 4, column 0: syntax error while parsing value - invalid string: control character U+000A (LF) must be escaped to \u000A or \n; last read: '"value without closing quotes<U+000A>' | ||
the input is invalid JSON |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# adl_serializer | ||
|
||
```cpp | ||
template<typename, typename> | ||
struct adl_serializer; | ||
``` | ||
|
||
Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose | ||
`to_json`/`from_json` functions from the types' namespaces. | ||
|
||
It is implemented similar to | ||
|
||
```cpp | ||
template<typename ValueType> | ||
struct adl_serializer { | ||
template<typename BasicJsonType> | ||
static void to_json(BasicJsonType& j, const T& value) { | ||
// calls the "to_json" method in T's namespace | ||
} | ||
|
||
template<typename BasicJsonType> | ||
static void from_json(const BasicJsonType& j, T& value) { | ||
// same thing, but with the "from_json" method | ||
} | ||
}; | ||
``` | ||
|
||
## Member functions | ||
|
||
- **from_json** - convert a JSON value to any value type | ||
- **to_json** - convert any value type to a JSON value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# basic_basic_json::exception | ||
# basic_json::exception | ||
|
||
```cpp | ||
class exception : public std::exception; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.