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>
Create an empty JSON value with a given type. The value will be default initialized with an empty value which depends on the type:
Value type | initial value |
null | null |
boolean | false |
string | "" |
number | 0 |
object | {} |
array | [] |
- Parameters
-
[in] | v | the type of the value to create |
- Complexity
- Constant.
- Exception safety
- Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
- Example
- The following code shows the constructor for different value_t values
2 #include <nlohmann/json.hpp>
9 json j_null(json::value_t::null);
10 json j_boolean(json::value_t::boolean);
11 json j_number_integer(json::value_t::number_integer);
12 json j_number_float(json::value_t::number_float);
13 json j_object(json::value_t::object);
14 json j_array(json::value_t::array);
15 json j_string(json::value_t::string);
18 std::cout << j_null <<
'\n';
19 std::cout << j_boolean <<
'\n';
20 std::cout << j_number_integer <<
'\n';
21 std::cout << j_number_float <<
'\n';
22 std::cout << j_object <<
'\n';
23 std::cout << j_array <<
'\n';
24 std::cout << j_string <<
'\n';
Output (play with this example online): null
false
0
0.0
{}
[]
""
The example code above can be translated withg++ -std=c++11 -Isingle_include doc/examples/basic_json__value_t.cpp -o basic_json__value_t
- See also
- clear() – restores the postcondition of this constructor
- Since
- version 1.0.0
Definition at line 15752 of file json.hpp.