JSON for Modern C++ 2.1.1
Loading...
Searching...
No Matches

◆ basic_json() [2/9]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::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\n Constant.
Exception safety\n No-throw guarantee: this constructor never throws
exceptions.
Example\n The following code shows the constructor with and without a
null pointer parameter.
1#include <json.hpp>
2
3using json = nlohmann::json;
4
5int main()
6{
7 // implicitly create a JSON null value
8 json j1;
9
10 // explicitly create a JSON null value
11 json j2(nullptr);
12
13 // serialize the JSON null value
14 std::cout << j1 << '\n' << j2 << '\n';
15}
static basic_json array(std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
explicitly create an array from an initializer list
Definition json.hpp:2165
a class to store JSON values
Definition json.hpp:1040
basic_json<> json
default JSON class
Definition json.hpp:12369

Output (play with this example online):
null
null

The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/basic_json__nullptr_t.cpp -o basic_json__nullptr_t 
Since
version 1.0.0

Definition at line 1940 of file json.hpp.