JSON for Modern C++ 3.0

- Main Page
- Related Pages
- Classes

allocator_type
array
array_t
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
boolean_t
cbegin
cend
clear
const_pointer
const_reference
count
crbegin
crend
difference_type
dump
empty
end
end
erase
erase
erase
erase
find
find
front
front
get
get
get
get_allocator
get_ptr
get_ptr
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_object
is_primitive
is_string
is_structured
max_size
number_float_t
number_integer_t
object
object_t
operator value_t
operator ValueType
operator!=
operator+=
operator+=
operator+=
operator<
operator<
operator<<
operator<<
operator<=
operator=
operator==
operator>
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
parse
parse
parse_event_t
parser_callback_t
pointer
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
size
size_type
string_t
swap
swap
swap
swap
type
value_t
value_type
~basic_json
| 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 | ) |
| 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 | the type of the value to create
  Complexity Constant. Exceptions
  std::bad_alloc | if 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 8 json j_null(json::value_t::null); 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 } nlohmann::basic_json a class to store JSON values Definition: json.hpp:130 nlohmann::basic_json::value_t::object object (unordered set of name/value pairs) nlohmann namespace for Niels Lohmann Definition: json.hpp:55 nlohmann::basic_json::value_t::string string value nlohmann::basic_json::value_t::array array (ordered collection of values) nlohmann::basic_json::value_t::null null value nlohmann::basic_json::value_t::number_float number value (floating-point) nlohmann::basic_json::value_t::boolean boolean value nlohmann::basic_json::value_t::number_integer number value (integer) Output (play with this example online):
      null
      false
      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