JSON for Modern C++ 2.0.0

- Main Page
- Classes

allocator_type
array
array_t
at
at
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
basic_json
basic_json
basic_json
begin
begin
boolean_t
cbegin
cend
clear
const_pointer
const_reference
const_reverse_iterator
count
crbegin
crend
diff
difference_type
dump
empty
end
end
erase
erase
erase
erase
find
find
flatten
front
front
get
get
get
get_allocator
get_ptr
get_ptr
get_ref
get_ref
insert
insert
insert
insert
insert
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_number_unsigned
is_object
is_primitive
is_string
is_structured
iterator_wrapper
iterator_wrapper
max_size
number_float_t
number_integer_t
number_unsigned_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[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
parse
parse
parse
parse_event_t
parser_callback_t
patch
pointer
push_back
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
size
size_type
string_t
swap
swap
swap
swap
type
unflatten
value
value
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 = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static basic_json nlohmann::basic_json::diff | ( | const basic_json & | source,
|  | const basic_json & | target,
|  | std::string | path = `""`
| ) |  |
| inline static noexcept
  Creates a JSON Patch so that value source can be changed into the value target by calling patch function. Invariant For two JSON values source and target, the following code yields always `true`: source.patch(diff(source, target)) == target; Note Currently, only `remove`, `add`, and `replace` operations are generated. Parameters
  [in] | source | JSON value to copare from
  [in] | target | JSON value to copare against
  [in] | path | helper value to create JSON pointers
  Returns a JSON patch to convert the source to target Complexity Linear in the lengths of source and target. Example The following code shows how a JSON patch is created as a diff for two JSON values. 1 #include <json.hpp> 2 3 using json = nlohmann::json; 4 5 int main() 6 { 7 // the source document 8 json source = R"( 9 { 10 "baz": "qux", 11 "foo": "bar" 12 } 13 )"_json; 14 15 // the target document 16 json target = R"( 17 { 18 "baz": "boo", 19 "hello": [ 20 "world" 21 ] 22 } 23 )"_json; 24 25 // create the patch 26 json patch = json::diff(source, target); 27 28 // roundtrip 29 json patched_source = source.patch(patch); 30 31 // output patch and roundtrip result 32 std::cout << std::setw(4) << patch << "\n\n" 33 << std::setw(4) << patched_source << std::endl; 34 } nlohmann::json basic_json<> json default JSON class Definition: json.hpp:10102 nlohmann::basic_json::diff static basic_json diff(const basic_json &source, const basic_json &target, std::string path="") noexcept creates a diff as a JSON patch Definition: json.hpp:9957 nlohmann::basic_json::patch basic_json patch(const basic_json &patch) const applies a JSON patch Definition: json.hpp:9664 Output (play with this example online):
      [
          {
              "op": "replace",
              "path": "/baz",
              "value": "boo"
          },
          {
              "op": "remove",
              "path": "/foo"
          },
          {
              "op": "add",
              "path": "/hello",
              "value": [
                  "world"
              ]
          }
      ]

      {
          "baz": "boo",
          "hello": [
              "world"
          ]
      }
  The example code above can be translated with
      g++ -std=c++11 -Isrc doc/examples/diff.cpp -o diff
See also patch – apply a JSON patch RFC 6902 (JSON Patch) Since version 2.0.0 Definition at line 9957 of file json.hpp.