JSON for Modern C++  1.1.0
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 = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json::basic_json ( const value_t  value_type)
inline

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]value_typethe type of the value to create
Complexity
Constant.
Exceptions
std::bad_allocif allocation for object, array, or string value fails
Example
The following code shows the constructor for different value_t values
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create the different JSON values with default values
9  json j_boolean(json::value_t::boolean);
10  json j_number_integer(json::value_t::number_integer);
11  json j_number_float(json::value_t::number_float);
12  json j_object(json::value_t::object);
13  json j_array(json::value_t::array);
14  json j_string(json::value_t::string);
15 
16  // serialize the JSON values
17  std::cout << j_null << '\n';
18  std::cout << j_boolean << '\n';
19  std::cout << j_number_integer << '\n';
20  std::cout << j_number_float << '\n';
21  std::cout << j_object << '\n';
22  std::cout << j_array << '\n';
23  std::cout << j_string << '\n';
24 }
a class to store JSON values
Definition: json.hpp:191
object (unordered set of name/value pairs)
namespace for Niels Lohmann
Definition: json.hpp:88
array (ordered collection of values)
number value (floating-point)
Output (play with this example online):
null
false
0
0.0
{}
[]
""
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/basic_json__value_t.cpp -o basic_json__value_t 
See also
basic_json(std::nullptr_t) – create a null value
basic_json(boolean_t value) – create a boolean value
basic_json(const string_t&) – create a string value
basic_json(const object_t&) – create a object value
basic_json(const array_t&) – create a array value
basic_json(const number_float_t) – create a number (floating-point) value
basic_json(const number_integer_t) – create a number (integer) value
Since
version 1.0.0

Definition at line 876 of file json.hpp.