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_allocator
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
list_init_t
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>

void nlohmann::basic_json::clear | ( |  | ) |

inlinenoexcept

Clears the content of a JSON value and resets it to the default value as if basic_json(value_t) would have been called:

Value type | initial value
--- | ---
null | `null`
boolean | `false`
string | `""`
number | `0`
object | `{}`
array | `[]`

Note
  Floating-point numbers are set to `0.0` which will be serialized to `0`. The vale type remains number_float_t.

Complexity
  Linear in the size of the JSON value.

Example
  The example below shows the effect of clear to different JSON types.
  #include <json.hpp>
  using namespace nlohmann;
  int main()
  {
  // create JSON values
  json j_null;
  json j_boolean = true;
  json j_number_integer = 17;
  json j_number_float = 23.42;
  json j_object = {{"one", 1}, {"two", 2}};
  json j_array = {1, 2, 4, 8, 16};
  json j_string = "Hello, world";
  // call clear()
  j_null.clear();
  j_boolean.clear();
  j_number_integer.clear();
  j_number_float.clear();
  j_object.clear();
  j_array.clear();
  j_string.clear();
  // serialize the cleared values()
  std::cout << j_null << '\n';
  std::cout << j_boolean << '\n';
  std::cout << j_number_integer << '\n';
  std::cout << j_number_float << '\n';
  std::cout << j_object << '\n';
  std::cout << j_array << '\n';
  std::cout << j_string << '\n';
  }
  nlohmann::basic_json::clear
  void clear() noexcept
  clears the contents
  Definition: json.hpp:3082
  nlohmann::basic_json
  a class to store JSON values
  Definition: json.hpp:121
  nlohmann
  namespace for Niels Lohmann
  Definition: json.hpp:56
  Output:

      null
      false
      0
      0
      {}
      []
      ""

  The example code above can be translated with

      g++ -std=c++11 -Isrc doc/examples/clear.cpp -o clear

  .