JSON for Modern C++  3.7.3

◆ basic_json() [2/9]

nlohmann::basic_json::basic_json ( std::nullptr_t  = nullptr)
inlinenoexcept

Create a null JSON value. It either takes a null pointer as parameter (explicitly creating null) or no parameter (implicitly creating null). The passed null pointer itself is not read – it is only used to choose the right constructor.

Complexity
Constant.
Exception safety
No-throw guarantee: this constructor never throws exceptions.
Example
The following code shows the constructor with and without a null pointer parameter.
1 #include <iostream>
2 #include <nlohmann/json.hpp>
3 
4 using json = nlohmann::json;
5 
6 int main()
7 {
8  // implicitly create a JSON null value
9  json j1;
10 
11  // explicitly create a JSON null value
12  json j2(nullptr);
13 
14  // serialize the JSON null value
15  std::cout << j1 << '\n' << j2 << '\n';
16 }

Output (play with this example online):
null
null
The example code above can be translated with
g++ -std=c++11 -Isingle_include doc/examples/basic_json__nullptr_t.cpp -o basic_json__nullptr_t 
Since
version 1.0.0

Definition at line 15776 of file json.hpp.

nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2445