├── docs ├── examples │ ├── begin.output │ ├── cbegin.output │ ├── cend.output │ ├── crend.output │ ├── end.output │ ├── rbegin.output │ ├── rend.output │ ├── array_t.output │ ├── binary_t.output │ ├── crbegin.output │ ├── object_t.output │ ├── string_t.output │ ├── boolean_t.output │ ├── number_float_t.output │ ├── number_integer_t.output │ ├── number_unsigned_t.output │ ├── accept__string.output │ ├── erase__size_type.output │ ├── get_ptr.output │ ├── insert.output │ ├── binary.output │ ├── get_allocator.output │ ├── basic_json__copyassignment.output │ ├── basic_json__nullptr_t.output │ ├── erase__keytype.c++17.output │ ├── get__PointerType.output │ ├── get_binary.output │ ├── insert__ilist.output │ ├── operator_array__keytype_const.c++17.output │ ├── operator_literal_json_pointer.output │ ├── value__json_ptr.output │ ├── basic_json__moveconstructor.output │ ├── erase__object_t_key_type.output │ ├── insert__count.output │ ├── operator_array__object_t_key_type_const.output │ ├── operator_array__size_type_const.output │ ├── operator_ltlt__json_pointer.output │ ├── to_string.output │ ├── value__keytype.c++17.output │ ├── value__object_t_key_type.output │ ├── json_pointer__operator_string_t.output │ ├── nlohmann_json_namespace_begin.c++17.output │ ├── operator__equal__specializations.output │ ├── json_pointer__string_t.output │ ├── nlohmann_json_namespace.output │ ├── nlohmann_json_namespace_no_version.output │ ├── array.output │ ├── clear.output │ ├── from_bson.output │ ├── from_cbor.output │ ├── front.output │ ├── nlohmann_json_version.output │ ├── sax_parse__binary.output │ ├── from_bjdata.output │ ├── from_msgpack.output │ ├── from_ubjson.output │ ├── insert__range.output │ ├── operator_array__json_pointer_const.output │ ├── parse__pointers.output │ ├── json_pointer__push_back.output │ ├── parse__iterator_pair.output │ ├── size.output │ ├── basic_json__value_t.output │ ├── default_object_comparator_t.output │ ├── json_pointer__pop_back.output │ ├── nlohmann_json_serialize_enum_2.output │ ├── operator_literal_json.output │ ├── ordered_json.output │ ├── push_back.output │ ├── type.output │ ├── json_pointer__operator_add_binary.output │ ├── swap__array_t.output │ ├── swap__string_t.output │ ├── to_json.output │ ├── erase__IteratorType.output │ ├── from_json__default_constructible.output │ ├── json_pointer__empty.output │ ├── max_size.output │ ├── basic_json__basic_json.output │ ├── contains__json_pointer.output │ ├── diagnostics_standard.output │ ├── from_json__non_default_constructible.output │ ├── operator__value_t.output │ ├── operator_array__size_type.output │ ├── swap__reference.output │ ├── byte_container_with_subtype__has_subtype.output │ ├── erase__IteratorType_IteratorType.output │ ├── parse__contiguouscontainer__parser_callback_t.output │ ├── basic_json__size_type_basic_json.output │ ├── byte_container_with_subtype__subtype.output │ ├── emplace_back.output │ ├── empty.output │ ├── find__keytype.c++17.output │ ├── parse__pointers.link │ ├── std_swap.output │ ├── to_bjdata.output │ ├── to_cbor.output │ ├── to_ubjson.output │ ├── count__keytype.c++17.output │ ├── exception.output │ ├── find__object_t_key_type.output │ ├── is_array.output │ ├── is_null.output │ ├── is_number.output │ ├── is_primitive.output │ ├── json_pointer__back.output │ ├── json_pointer__operator_add.output │ ├── parse__iterator_pair.link │ ├── swap__binary_t.output │ ├── to_msgpack.output │ ├── count__object_t_key_type.output │ ├── is_binary.output │ ├── is_boolean.output │ ├── is_discarded.output │ ├── is_object.output │ ├── is_string.output │ ├── is_structured.output │ ├── json_pointer__parent_pointer.output │ ├── out_of_range.output │ ├── swap__object_t.output │ ├── type_error.output │ ├── diagnostics_extended.output │ ├── emplace.output │ ├── get_ref.output │ ├── is_number_float.output │ ├── is_number_integer.output │ ├── is_number_unsigned.output │ ├── push_back__initializer_list.output │ ├── at__keytype_const.c++17.output │ ├── back.output │ ├── json_pointer__operator__equal.output │ ├── object.output │ ├── push_back__object_t__value.output │ ├── at__object_t_key_type_const.output │ ├── basic_json__list_init_t.output │ ├── json_pointer__operator__notequal.output │ ├── object_comparator_t.output │ ├── contains__keytype.c++17.output │ ├── invalid_iterator.output │ ├── contains__object_t_key_type.output │ ├── nlohmann_define_type_intrusive_only_serialize_macro.output │ ├── operator__equal.output │ ├── basic_json__InputIt_InputIt.output │ ├── nlohmann_define_type_intrusive_only_serialize_explicit.output │ ├── nlohmann_define_type_non_intrusive_only_serialize_macro.output │ ├── operator__notequal.output │ ├── nlohmann_define_type_non_intrusive_only_serialize_explicit.output │ ├── nlohmann_json_serialize_enum.output │ ├── to_bson.output │ ├── operator__greater.output │ ├── operator__less.output │ ├── operator__lessequal.output │ ├── items.output │ ├── operator__greaterequal.output │ ├── operator_spaceship__scalartype.c++20.output │ ├── other_error.output │ ├── patch.output │ ├── at__size_type_const.output │ ├── insert__range_object.output │ ├── json_pointer__to_string.output │ ├── operator__equal__nullptr_t.output │ ├── operator__notequal__nullptr_t.output │ ├── byte_container_with_subtype__byte_container_with_subtype.output │ ├── operator_array__json_pointer.output │ ├── error_handler_t.output │ ├── json_base_class_t.output │ ├── patch_inplace.output │ ├── at__size_type.output │ ├── byte_container_with_subtype__clear_subtype.output │ ├── byte_container_with_subtype__set_subtype.output │ ├── operator_spaceship__const_reference.c++20.output │ ├── ordered_map.output │ ├── nlohmann_define_type_intrusive_explicit.output │ ├── nlohmann_define_type_intrusive_macro.output │ ├── type_name.output │ ├── nlohmann_define_type_non_intrusive_explicit.output │ ├── nlohmann_define_type_non_intrusive_macro.output │ ├── get_to.output │ ├── nlohmann_define_type_intrusive_with_default_explicit.output │ ├── nlohmann_define_type_intrusive_with_default_macro.output │ ├── operator_deserialize.output │ ├── nlohmann_define_type_non_intrusive_with_default_explicit.output │ ├── nlohmann_define_type_non_intrusive_with_default_macro.output │ ├── parse_error.output │ ├── cbor_tag_handler_t.output │ ├── json_lines.output │ ├── at__keytype.c++17.output │ ├── get__ValueType_const.output │ ├── at__object_t_key_type.output │ ├── json_pointer__operator__equal_stringtype.output │ ├── json_pointer__operator__notequal_stringtype.output │ ├── meta.cpp │ ├── operator_ltlt__basic_json.output │ ├── std_hash.output │ ├── boolean_t.cpp │ ├── merge_patch.output │ ├── array_t.cpp │ ├── string_t.cpp │ ├── number_float_t.cpp │ ├── number_integer_t.cpp │ ├── object_t.cpp │ ├── number_unsigned_t.cpp │ ├── parse__allow_exceptions.output │ ├── flatten.output │ ├── update.output │ ├── operator__ValueType.output │ ├── ordered_json.cpp │ ├── update__range.output │ ├── binary_t.cpp │ ├── operator_array__keytype.c++17.output │ ├── operator_array__object_t_key_type.output │ ├── operator_ltlt__json_pointer.cpp │ ├── json_pointer.output │ ├── operator_literal_json.cpp │ ├── erase__size_type.cpp │ ├── unflatten.output │ ├── operator_array__size_type_const.cpp │ ├── nlohmann_json_namespace_no_version.cpp │ ├── nlohmann_json_version.cpp │ ├── json_pointer__string_t.cpp │ ├── basic_json__copyassignment.cpp │ ├── basic_json__moveconstructor.cpp │ ├── basic_json__nullptr_t.cpp │ ├── operator_literal_json_pointer.cpp │ ├── operator_array__object_t_key_type_const.cpp │ ├── default_object_comparator_t.cpp │ ├── begin.cpp │ ├── at__json_pointer_const.output │ ├── cbegin.cpp │ ├── rbegin.cpp │ ├── crbegin.cpp │ ├── insert.cpp │ ├── basic_json__basic_json.cpp │ ├── diff.output │ ├── nlohmann_json_namespace.cpp │ ├── object_comparator_t.cpp │ ├── parse__pointers.cpp │ ├── insert__ilist.cpp │ ├── json_pointer__operator_string_t.cpp │ ├── meta.output │ ├── insert__count.cpp │ ├── diagnostics_standard.cpp │ ├── operator_array__keytype_const.c++17.cpp │ ├── swap__reference.cpp │ ├── parse__contiguouscontainer__parser_callback_t.cpp │ ├── std_swap.cpp │ ├── binary.cpp │ ├── get_binary.cpp │ ├── end.cpp │ ├── get_allocator.cpp │ ├── rend.cpp │ ├── cend.cpp │ ├── crend.cpp │ ├── diagnostics_extended.cpp │ ├── erase__object_t_key_type.cpp │ ├── json_pointer__back.cpp │ ├── parse__array__parser_callback_t.output │ ├── parse__iterator_pair.cpp │ ├── at__json_pointer.output │ ├── out_of_range.cpp │ ├── basic_json__size_type_basic_json.cpp │ ├── type_error.cpp │ ├── README.output │ ├── exception.cpp │ ├── json_pointer__operator_add_binary.cpp │ ├── json_pointer__pop_back.cpp │ ├── json_pointer__push_back.cpp │ ├── swap__binary_t.cpp │ ├── swap__string_t.cpp │ ├── swap__array_t.cpp │ ├── parse_error.cpp │ ├── push_back.cpp │ ├── count__object_t_key_type.cpp │ ├── emplace_back.cpp │ ├── insert__range_object.cpp │ ├── to_string.cpp │ ├── erase__keytype.c++17.cpp │ ├── insert__range.cpp │ ├── operator__equal__specializations.cpp │ ├── invalid_iterator.cpp │ ├── swap__object_t.cpp │ ├── accept__string.cpp │ ├── to_bson.cpp │ ├── to_cbor.cpp │ ├── items.cpp │ ├── json_pointer__operator_add.cpp │ ├── operator_array__size_type.cpp │ ├── to_msgpack.cpp │ ├── array.cpp │ ├── count__keytype.c++17.cpp │ ├── from_cbor.cpp │ ├── from_msgpack.cpp │ ├── find__object_t_key_type.cpp │ ├── operator_deserialize.cpp │ ├── json_lines.cpp │ ├── operator_ltlt__basic_json.cpp │ ├── contains__object_t_key_type.cpp │ ├── nlohmann_define_type_non_intrusive_only_serialize_macro.cpp │ ├── to_json.cpp │ ├── from_bjdata.cpp │ ├── from_ubjson.cpp │ ├── json_pointer__parent_pointer.cpp │ ├── unflatten.cpp │ ├── json_pointer__empty.cpp │ ├── basic_json__list_init_t.cpp │ ├── byte_container_with_subtype__clear_subtype.cpp │ ├── get_ref.cpp │ ├── byte_container_with_subtype__has_subtype.cpp │ ├── push_back__object_t__value.cpp │ ├── byte_container_with_subtype__set_subtype.cpp │ ├── dump.output │ ├── find__keytype.c++17.cpp │ ├── from_bson.cpp │ ├── get_ptr.cpp │ ├── contains__keytype.c++17.cpp │ ├── flatten.cpp │ └── json_pointer__operator__equal.cpp ├── json.gif ├── avatars.png ├── mkdocs │ └── docs │ │ ├── index.md │ │ ├── integration │ │ ├── conan │ │ │ ├── Conanfile.txt │ │ │ ├── example.cpp │ │ │ └── CMakeLists.txt │ │ ├── vcpkg │ │ │ ├── example.cpp │ │ │ └── CMakeLists.txt │ │ ├── example.cpp │ │ ├── pkg-config.md │ │ └── index.md │ │ ├── images │ │ ├── callback_events.png │ │ └── json_syntax_number.png │ │ ├── css │ │ └── custom.css │ │ ├── features │ │ ├── parsing │ │ │ └── index.md │ │ └── element_access │ │ │ └── index.md │ │ ├── api │ │ ├── basic_json │ │ │ ├── ~basic_json.md │ │ │ └── get_allocator.md │ │ ├── json_sax │ │ │ ├── null.md │ │ │ ├── end_array.md │ │ │ ├── end_object.md │ │ │ ├── boolean.md │ │ │ ├── number_integer.md │ │ │ ├── number_unsigned.md │ │ │ ├── key.md │ │ │ └── string.md │ │ ├── json.md │ │ ├── ordered_json.md │ │ └── json_pointer │ │ │ ├── string_t.md │ │ │ └── pop_back.md │ │ └── home │ │ └── sponsors.md ├── docset │ ├── icon.png │ ├── icon@2x.png │ ├── docset.json │ └── Info.plist └── usages │ ├── ios.png │ └── macos.png ├── tests ├── thirdparty │ └── Fuzzer │ │ ├── test │ │ ├── hi.txt │ │ ├── ulimit.test │ │ ├── dict1.txt │ │ ├── swap-cmp.test │ │ ├── simple-cmp.test │ │ ├── repeated-bytes.test │ │ ├── value-profile-cmp.test │ │ ├── unit │ │ │ ├── lit.site.cfg.in │ │ │ └── lit.cfg │ │ ├── value-profile-cmp2.test │ │ ├── value-profile-div.test │ │ ├── value-profile-cmp3.test │ │ ├── value-profile-cmp4.test │ │ ├── caller-callee.test │ │ ├── fuzzer-seed.test │ │ ├── value-profile-mem.test │ │ ├── value-profile-set.test │ │ ├── value-profile-strcmp.test │ │ ├── value-profile-strncmp.test │ │ ├── value-profile-load.test │ │ ├── fuzzer-custommutator.test │ │ ├── fuzzer-ubsan.test │ │ ├── fuzzer-printcovpcs.test │ │ ├── lit.site.cfg.in │ │ ├── standalone.test │ │ ├── value-profile-switch.test │ │ ├── DSOTestExtra.cpp │ │ ├── DSO1.cpp │ │ ├── DSO2.cpp │ │ ├── fuzzer-oom-with-profile.test │ │ ├── fuzzer-dict.test │ │ ├── fuzzer-segv.test │ │ ├── EmptyTest.cpp │ │ ├── fuzzer-runs.test │ │ ├── UninstrumentedTest.cpp │ │ ├── fuzzer-threaded.test │ │ ├── LeakTest.cpp │ │ ├── TimeoutEmptyTest.cpp │ │ ├── afl-driver-stderr.test │ │ ├── ubsan │ │ │ └── CMakeLists.txt │ │ ├── LeakTimeoutTest.cpp │ │ ├── fuzzer-customcrossover.test │ │ ├── NthRunCrashTest.cpp │ │ ├── trace-malloc.test │ │ ├── ThreadedLeakTest.cpp │ │ ├── SingleStrcmpTest.cpp │ │ ├── SingleMemcmpTest.cpp │ │ ├── SingleStrncmpTest.cpp │ │ ├── CounterTest.cpp │ │ ├── fuzzer-flags.test │ │ ├── NullDerefOnEmptyTest.cpp │ │ ├── DivTest.cpp │ │ ├── fuzzer-finalstats.test │ │ ├── minimize_crash.test │ │ ├── uninstrumented │ │ │ └── CMakeLists.txt │ │ ├── fuzzer-oom.test │ │ ├── AccumulateAllocationsTest.cpp │ │ ├── RepeatedMemcmp.cpp │ │ ├── SpamyTest.cpp │ │ ├── LoadTest.cpp │ │ ├── StrncmpOOBTest.cpp │ │ ├── TraceMallocTest.cpp │ │ ├── AbsNegAndConstantTest.cpp │ │ ├── AFLDriverTest.cpp │ │ ├── BufferOverflowOnInput.cpp │ │ ├── TimeoutTest.cpp │ │ └── ShrinkValueProfileTest.cpp │ │ ├── README.txt │ │ └── build.sh ├── reports │ ├── 2016-08-29-fuzz │ │ ├── fuzz.tiff │ │ ├── high_freq.png │ │ ├── low_freq.png │ │ ├── exec_speed.png │ │ └── index.html │ ├── 2016-10-02-fuzz │ │ ├── fuzz.tiff │ │ ├── high_freq.png │ │ ├── low_freq.png │ │ ├── exec_speed.png │ │ └── index.html │ └── 2016-09-09-nativejson_benchmark │ │ ├── conformance_overall_Result.png │ │ ├── performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_1._Parse_Time_(ms).png │ │ ├── performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_1._Parse_Memory_(byte).png │ │ ├── performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_2._Stringify_Time_(ms).png │ │ ├── performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_3._Prettify_Time_(ms).png │ │ └── performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_7._Code_size_FileSize_(byte).png ├── cmake_import_minver │ ├── project │ │ ├── CMakeLists.txt │ │ └── main.cpp │ └── CMakeLists.txt ├── cuda_example │ ├── CMakeLists.txt │ └── json_cuda.cu ├── cmake_import │ ├── project │ │ ├── CMakeLists.txt │ │ └── main.cpp │ └── CMakeLists.txt ├── cmake_target_include_directories │ └── project │ │ ├── Bar.cpp │ │ ├── Foo.cpp │ │ ├── Foo.hpp │ │ ├── Bar.hpp │ │ └── main.cpp ├── src │ ├── unit.cpp │ └── unit-windows_h.cpp ├── abi │ ├── inline_ns │ │ └── CMakeLists.txt │ ├── main.cpp │ └── diag │ │ └── diag.hpp ├── cmake_add_subdirectory │ ├── project │ │ └── main.cpp │ └── CMakeLists.txt ├── cmake_fetch_content │ └── project │ │ └── main.cpp └── cmake_fetch_content2 │ └── project │ ├── main.cpp │ └── CMakeLists.txt ├── WORKSPACE.bazel ├── tools ├── serve_header │ ├── requirements.txt │ ├── demo.png │ └── serve_header.yml.example ├── amalgamate │ ├── config_json.json │ ├── config_json_fwd.json │ └── CHANGES.md └── generate_natvis │ └── README.md ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── config.yml ├── CODEOWNERS ├── workflows │ └── labeler.yml ├── SECURITY.md └── labeler.yml ├── .lgtm.yml ├── cmake ├── pkg-config.pc.in └── scripts │ └── gen_bazel_build_file.cmake ├── .reuse ├── README.md └── templates │ ├── json.jinja2 │ └── json_support.jinja2 ├── CITATION.cff ├── .cirrus.yml ├── include └── nlohmann │ └── detail │ └── meta │ ├── call_std │ ├── end.hpp │ └── begin.hpp │ ├── identity_tag.hpp │ └── void_t.hpp ├── Package.swift ├── wsjcpp.yml └── meson.build /docs/examples/begin.output: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /docs/examples/cbegin.output: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /docs/examples/cend.output: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /docs/examples/crend.output: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /docs/examples/end.output: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /docs/examples/rbegin.output: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /docs/examples/rend.output: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /docs/examples/array_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /docs/examples/binary_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /docs/examples/crbegin.output: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /docs/examples/object_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /docs/examples/string_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/hi.txt: -------------------------------------------------------------------------------- 1 | Hi! -------------------------------------------------------------------------------- /docs/examples/boolean_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /docs/examples/number_float_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /docs/examples/number_integer_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /docs/examples/number_unsigned_t.output: -------------------------------------------------------------------------------- 1 | true 2 | -------------------------------------------------------------------------------- /WORKSPACE.bazel: -------------------------------------------------------------------------------- 1 | workspace(name = "nlohmann_json") 2 | -------------------------------------------------------------------------------- /docs/examples/accept__string.output: -------------------------------------------------------------------------------- 1 | true false 2 | -------------------------------------------------------------------------------- /docs/examples/erase__size_type.output: -------------------------------------------------------------------------------- 1 | [0,1,3,4,5] 2 | -------------------------------------------------------------------------------- /docs/examples/get_ptr.output: -------------------------------------------------------------------------------- 1 | 17 17 17 17 2 | true 3 | -------------------------------------------------------------------------------- /docs/examples/insert.output: -------------------------------------------------------------------------------- 1 | 10 2 | [1,2,10,3,4] 3 | -------------------------------------------------------------------------------- /docs/examples/binary.output: -------------------------------------------------------------------------------- 1 | type: binary, subtype: 42 2 | -------------------------------------------------------------------------------- /docs/examples/get_allocator.output: -------------------------------------------------------------------------------- 1 | "Hello, world!" 2 | -------------------------------------------------------------------------------- /docs/examples/basic_json__copyassignment.output: -------------------------------------------------------------------------------- 1 | 23 2 | 23 3 | -------------------------------------------------------------------------------- /docs/examples/basic_json__nullptr_t.output: -------------------------------------------------------------------------------- 1 | null 2 | null 3 | -------------------------------------------------------------------------------- /docs/examples/erase__keytype.c++17.output: -------------------------------------------------------------------------------- 1 | {"two":2} 2 | 1 0 3 | -------------------------------------------------------------------------------- /docs/examples/get__PointerType.output: -------------------------------------------------------------------------------- 1 | 17 17 17 17 2 | true 3 | -------------------------------------------------------------------------------- /docs/examples/get_binary.output: -------------------------------------------------------------------------------- 1 | type: binary, subtype: 42 2 | -------------------------------------------------------------------------------- /docs/examples/insert__ilist.output: -------------------------------------------------------------------------------- 1 | 7 2 | [1,2,3,4,7,8,9] 3 | -------------------------------------------------------------------------------- /docs/examples/operator_array__keytype_const.c++17.output: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /docs/examples/operator_literal_json_pointer.output: -------------------------------------------------------------------------------- 1 | "world" 2 | -------------------------------------------------------------------------------- /docs/examples/value__json_ptr.output: -------------------------------------------------------------------------------- 1 | 1 42.23 oops false 2 | -------------------------------------------------------------------------------- /docs/examples/basic_json__moveconstructor.output: -------------------------------------------------------------------------------- 1 | null 2 | 23 3 | -------------------------------------------------------------------------------- /docs/examples/erase__object_t_key_type.output: -------------------------------------------------------------------------------- 1 | {"two":2} 2 | 1 0 3 | -------------------------------------------------------------------------------- /docs/examples/insert__count.output: -------------------------------------------------------------------------------- 1 | 7 2 | [1,2,7,7,7,7,7,7,7,3,4] 3 | -------------------------------------------------------------------------------- /docs/examples/operator_array__object_t_key_type_const.output: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /docs/examples/operator_array__size_type_const.output: -------------------------------------------------------------------------------- 1 | "third" 2 | -------------------------------------------------------------------------------- /docs/examples/operator_ltlt__json_pointer.output: -------------------------------------------------------------------------------- 1 | /foo/bar/baz 2 | -------------------------------------------------------------------------------- /docs/examples/to_string.output: -------------------------------------------------------------------------------- 1 | {"one":1,"two":2} 2 | 3 | 42 4 | -------------------------------------------------------------------------------- /docs/examples/value__keytype.c++17.output: -------------------------------------------------------------------------------- 1 | 1 42.23 oops false 2 | -------------------------------------------------------------------------------- /docs/examples/value__object_t_key_type.output: -------------------------------------------------------------------------------- 1 | 1 42.23 oops false 2 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator_string_t.output: -------------------------------------------------------------------------------- 1 | /foo/0 2 | /a~1b 3 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_namespace_begin.c++17.output: -------------------------------------------------------------------------------- 1 | [1,null] 2 | -------------------------------------------------------------------------------- /docs/examples/operator__equal__specializations.output: -------------------------------------------------------------------------------- 1 | true 2 | false 3 | -------------------------------------------------------------------------------- /tools/serve_header/requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML==6.0 2 | watchdog==2.1.7 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: nlohmann 2 | custom: http://paypal.me/nlohmann 3 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__string_t.output: -------------------------------------------------------------------------------- 1 | This is a string. 2 | true 3 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_namespace.output: -------------------------------------------------------------------------------- 1 | nlohmann::json_abi_v3_11_3 2 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_namespace_no_version.output: -------------------------------------------------------------------------------- 1 | nlohmann::json_abi 2 | -------------------------------------------------------------------------------- /docs/json.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/json.gif -------------------------------------------------------------------------------- /docs/avatars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/avatars.png -------------------------------------------------------------------------------- /docs/examples/array.output: -------------------------------------------------------------------------------- 1 | [] 2 | [] 3 | [1,2,3,4] 4 | [["one",1],["two",2]] 5 | -------------------------------------------------------------------------------- /docs/examples/clear.output: -------------------------------------------------------------------------------- 1 | null 2 | false 3 | 0 4 | 0.0 5 | {} 6 | [] 7 | "" 8 | -------------------------------------------------------------------------------- /docs/examples/from_bson.output: -------------------------------------------------------------------------------- 1 | { 2 | "compact": true, 3 | "schema": 0 4 | } 5 | -------------------------------------------------------------------------------- /docs/examples/from_cbor.output: -------------------------------------------------------------------------------- 1 | { 2 | "compact": true, 3 | "schema": 0 4 | } 5 | -------------------------------------------------------------------------------- /docs/examples/front.output: -------------------------------------------------------------------------------- 1 | true 2 | 17 3 | 23.42 4 | 1 5 | 1 6 | "Hello, world" 7 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_version.output: -------------------------------------------------------------------------------- 1 | JSON for Modern C++ version 3.11.3 2 | -------------------------------------------------------------------------------- /docs/examples/sax_parse__binary.output: -------------------------------------------------------------------------------- 1 | binary(val=[...]) 2 | 3 | result: true 4 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/index.md: -------------------------------------------------------------------------------- 1 | # JSON for Modern C++ 2 | 3 | ![](images/json.gif) 4 | -------------------------------------------------------------------------------- /docs/examples/from_bjdata.output: -------------------------------------------------------------------------------- 1 | { 2 | "compact": true, 3 | "schema": 0 4 | } 5 | -------------------------------------------------------------------------------- /docs/examples/from_msgpack.output: -------------------------------------------------------------------------------- 1 | { 2 | "compact": true, 3 | "schema": 0 4 | } 5 | -------------------------------------------------------------------------------- /docs/examples/from_ubjson.output: -------------------------------------------------------------------------------- 1 | { 2 | "compact": true, 3 | "schema": 0 4 | } 5 | -------------------------------------------------------------------------------- /docs/examples/insert__range.output: -------------------------------------------------------------------------------- 1 | "one" 2 | [1,2,3,4,"one","two","three","four"] 3 | -------------------------------------------------------------------------------- /docs/examples/operator_array__json_pointer_const.output: -------------------------------------------------------------------------------- 1 | 1 2 | "foo" 3 | [1,2] 4 | 2 5 | -------------------------------------------------------------------------------- /docs/examples/parse__pointers.output: -------------------------------------------------------------------------------- 1 | [ 2 | 1, 3 | 2, 4 | 3 5 | ] 6 | 7 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/README.txt: -------------------------------------------------------------------------------- 1 | Move to http://llvm.org/docs/LibFuzzer.html 2 | 3 | -------------------------------------------------------------------------------- /docs/docset/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/docset/icon.png -------------------------------------------------------------------------------- /docs/examples/json_pointer__push_back.output: -------------------------------------------------------------------------------- 1 | "" 2 | "/foo" 3 | "/foo/0" 4 | "/foo/0/bar" 5 | -------------------------------------------------------------------------------- /docs/examples/parse__iterator_pair.output: -------------------------------------------------------------------------------- 1 | [ 2 | 1, 3 | 2, 4 | 3 5 | ] 6 | 7 | -------------------------------------------------------------------------------- /docs/examples/size.output: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 1 4 | 1 5 | 2 6 | 0 7 | 5 8 | 0 9 | 1 10 | -------------------------------------------------------------------------------- /docs/usages/ios.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/usages/ios.png -------------------------------------------------------------------------------- /docs/usages/macos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/usages/macos.png -------------------------------------------------------------------------------- /docs/docset/icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/docset/icon@2x.png -------------------------------------------------------------------------------- /docs/examples/basic_json__value_t.output: -------------------------------------------------------------------------------- 1 | null 2 | false 3 | 0 4 | 0.0 5 | {} 6 | [] 7 | "" 8 | -------------------------------------------------------------------------------- /docs/examples/default_object_comparator_t.output: -------------------------------------------------------------------------------- 1 | one < two : true 2 | three < four : false 3 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__pop_back.output: -------------------------------------------------------------------------------- 1 | "/foo/bar/baz" 2 | "/foo/bar" 3 | "/foo" 4 | "" 5 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_serialize_enum_2.output: -------------------------------------------------------------------------------- 1 | 0 -> "red" 2 | "rot" -> 0 3 | "red" -> 0 4 | -------------------------------------------------------------------------------- /docs/examples/operator_literal_json.output: -------------------------------------------------------------------------------- 1 | { 2 | "answer": 42, 3 | "hello": "world" 4 | } 5 | -------------------------------------------------------------------------------- /docs/examples/ordered_json.output: -------------------------------------------------------------------------------- 1 | { 2 | "one": 1, 3 | "two": 2, 4 | "three": 3 5 | } 6 | -------------------------------------------------------------------------------- /docs/examples/push_back.output: -------------------------------------------------------------------------------- 1 | [1,2,3,4,5] 2 | null 3 | [1,2,3,4,5,6,7] 4 | ["first","second"] 5 | -------------------------------------------------------------------------------- /docs/examples/type.output: -------------------------------------------------------------------------------- 1 | true 2 | true 3 | true 4 | true 5 | true 6 | true 7 | true 8 | true 9 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/ulimit.test: -------------------------------------------------------------------------------- 1 | RUN: ulimit -s 1000 2 | RUN: LLVMFuzzer-SimpleTest 3 | -------------------------------------------------------------------------------- /.lgtm.yml: -------------------------------------------------------------------------------- 1 | path_classifiers: 2 | thirdparty: 3 | - /tools/amalgamate 4 | - /tools/cpplint 5 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator_add_binary.output: -------------------------------------------------------------------------------- 1 | "/foo/bar/baz" 2 | "/foo/fob" 3 | "/foo/42" 4 | -------------------------------------------------------------------------------- /docs/examples/swap__array_t.output: -------------------------------------------------------------------------------- 1 | value = {"array":["Snap","Crackle","Pop"]} 2 | array = [1,2,3,4] 3 | -------------------------------------------------------------------------------- /docs/examples/swap__string_t.output: -------------------------------------------------------------------------------- 1 | value = ["the good","the fast","the ugly"] 2 | string = the bad 3 | -------------------------------------------------------------------------------- /docs/examples/to_json.output: -------------------------------------------------------------------------------- 1 | {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | -------------------------------------------------------------------------------- /docs/examples/erase__IteratorType.output: -------------------------------------------------------------------------------- 1 | null 2 | null 3 | null 4 | {"one":1} 5 | [1,2,8,16] 6 | null 7 | -------------------------------------------------------------------------------- /docs/examples/from_json__default_constructible.output: -------------------------------------------------------------------------------- 1 | Ned Flanders (60) lives in 744 Evergreen Terrace 2 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__empty.output: -------------------------------------------------------------------------------- 1 | "": true 2 | "": true 3 | "/foo": false 4 | "/foo/0": false 5 | -------------------------------------------------------------------------------- /docs/examples/max_size.output: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 1 4 | 1 5 | 115292150460684697 6 | 576460752303423487 7 | 1 8 | -------------------------------------------------------------------------------- /tools/serve_header/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tools/serve_header/demo.png -------------------------------------------------------------------------------- /docs/examples/basic_json__basic_json.output: -------------------------------------------------------------------------------- 1 | ["one","two",3,4.5,false] = ["one","two",3,4.5,false] 2 | true 3 | -------------------------------------------------------------------------------- /docs/examples/contains__json_pointer.output: -------------------------------------------------------------------------------- 1 | true 2 | true 3 | true 4 | true 5 | false 6 | false 7 | false 8 | -------------------------------------------------------------------------------- /docs/examples/diagnostics_standard.output: -------------------------------------------------------------------------------- 1 | [json.exception.type_error.302] type must be number, but is string 2 | -------------------------------------------------------------------------------- /docs/examples/from_json__non_default_constructible.output: -------------------------------------------------------------------------------- 1 | Ned Flanders (60) lives in 744 Evergreen Terrace 2 | -------------------------------------------------------------------------------- /docs/examples/operator__value_t.output: -------------------------------------------------------------------------------- 1 | true 2 | true 3 | true 4 | true 5 | true 6 | true 7 | true 8 | true 9 | -------------------------------------------------------------------------------- /docs/examples/operator_array__size_type.output: -------------------------------------------------------------------------------- 1 | 4 2 | [1,2,3,4,6] 3 | [1,2,3,4,6,null,null,null,null,null,11] 4 | -------------------------------------------------------------------------------- /docs/examples/swap__reference.output: -------------------------------------------------------------------------------- 1 | j1 = {"e":2.718281828459045,"pi":3.141592653589793} 2 | j2 = [1,2,3,4,5] 3 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__has_subtype.output: -------------------------------------------------------------------------------- 1 | c1.has_subtype() = false 2 | c2.has_subtype() = true 3 | -------------------------------------------------------------------------------- /docs/examples/erase__IteratorType_IteratorType.output: -------------------------------------------------------------------------------- 1 | null 2 | null 3 | null 4 | {"one":1} 5 | [1,8,16] 6 | null 7 | -------------------------------------------------------------------------------- /docs/examples/parse__contiguouscontainer__parser_callback_t.output: -------------------------------------------------------------------------------- 1 | [ 2 | 1, 3 | 2, 4 | 3 5 | ] 6 | 7 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/dict1.txt: -------------------------------------------------------------------------------- 1 | # Dictionary for SimpleDictionaryTest 2 | 3 | a="Elvis" 4 | b="Presley" 5 | -------------------------------------------------------------------------------- /docs/examples/basic_json__size_type_basic_json.output: -------------------------------------------------------------------------------- 1 | [] 2 | ["Hello"] 3 | ["Hello","Hello","Hello","Hello","Hello"] 4 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__subtype.output: -------------------------------------------------------------------------------- 1 | c1.subtype() = 18446744073709551615 2 | c2.subtype() = 42 3 | -------------------------------------------------------------------------------- /docs/examples/emplace_back.output: -------------------------------------------------------------------------------- 1 | [1,2,3,4,5] 2 | null 3 | [1,2,3,4,5,6] 4 | ["first",["second","second","second"]] 5 | -------------------------------------------------------------------------------- /docs/examples/empty.output: -------------------------------------------------------------------------------- 1 | true 2 | false 3 | false 4 | false 5 | false 6 | true 7 | false 8 | true 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/find__keytype.c++17.output: -------------------------------------------------------------------------------- 1 | "two" was found: true 2 | value at key "two": 2 3 | "three" was found: false 4 | -------------------------------------------------------------------------------- /docs/examples/parse__pointers.link: -------------------------------------------------------------------------------- 1 | online -------------------------------------------------------------------------------- /docs/examples/std_swap.output: -------------------------------------------------------------------------------- 1 | j1 = {"one":1,"two":2} | j2 = [1,2,4,8,16] 2 | j1 = [1,2,4,8,16] | j2 = {"one":1,"two":2} 3 | -------------------------------------------------------------------------------- /docs/examples/to_bjdata.output: -------------------------------------------------------------------------------- 1 | {i7compactTi6schemaF} 2 | [i1i2i3i4i5i6i7i8] 3 | [#i8i1i2i3i4i5i6i7i8 4 | [$i#i812345678 5 | -------------------------------------------------------------------------------- /docs/examples/to_cbor.output: -------------------------------------------------------------------------------- 1 | 0xa2 0x67 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0xf5 0x66 0x73 0x63 0x68 0x65 0x6d 0x61 0x00 2 | -------------------------------------------------------------------------------- /docs/examples/to_ubjson.output: -------------------------------------------------------------------------------- 1 | {i7compactTi6schemaF} 2 | [i1i2i3i4i5i6i7i8] 3 | [#i8i1i2i3i4i5i6i7i8 4 | [$i#i812345678 5 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/conan/Conanfile.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | nlohmann_json/3.7.3 3 | 4 | [generators] 5 | cmake 6 | -------------------------------------------------------------------------------- /docs/examples/count__keytype.c++17.output: -------------------------------------------------------------------------------- 1 | number of elements with key "two": 1 2 | number of elements with key "three": 0 3 | -------------------------------------------------------------------------------- /docs/examples/exception.output: -------------------------------------------------------------------------------- 1 | message: [json.exception.out_of_range.403] key 'non-existing' not found 2 | exception id: 403 3 | -------------------------------------------------------------------------------- /docs/examples/find__object_t_key_type.output: -------------------------------------------------------------------------------- 1 | "two" was found: true 2 | value at key "two": 2 3 | "three" was found: false 4 | -------------------------------------------------------------------------------- /docs/examples/is_array.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | false 5 | false 6 | false 7 | true 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_null.output: -------------------------------------------------------------------------------- 1 | true 2 | false 3 | false 4 | false 5 | false 6 | false 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_number.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | true 4 | true 5 | true 6 | false 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_primitive.output: -------------------------------------------------------------------------------- 1 | true 2 | true 3 | true 4 | true 5 | true 6 | false 7 | false 8 | true 9 | true 10 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__back.output: -------------------------------------------------------------------------------- 1 | last reference token of "/foo" is "foo" 2 | last reference token of "/foo/0" is "0" 3 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator_add.output: -------------------------------------------------------------------------------- 1 | "/foo" 2 | "/foo/bar/baz" 3 | "/foo/bar/baz/fob" 4 | "/foo/bar/baz/fob/42" 5 | -------------------------------------------------------------------------------- /docs/examples/parse__iterator_pair.link: -------------------------------------------------------------------------------- 1 | online -------------------------------------------------------------------------------- /docs/examples/swap__binary_t.output: -------------------------------------------------------------------------------- 1 | value = {"bytes":[4,5,6],"subtype":null} 2 | binary = {"bytes":[1,2,3],"subtype":null} 3 | -------------------------------------------------------------------------------- /docs/examples/to_msgpack.output: -------------------------------------------------------------------------------- 1 | 0x82 0xa7 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0xc3 0xa6 0x73 0x63 0x68 0x65 0x6d 0x61 0x00 2 | -------------------------------------------------------------------------------- /docs/examples/count__object_t_key_type.output: -------------------------------------------------------------------------------- 1 | number of elements with key "two": 1 2 | number of elements with key "three": 0 3 | -------------------------------------------------------------------------------- /docs/examples/is_binary.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | false 5 | false 6 | false 7 | false 8 | false 9 | true 10 | -------------------------------------------------------------------------------- /docs/examples/is_boolean.output: -------------------------------------------------------------------------------- 1 | false 2 | true 3 | false 4 | false 5 | false 6 | false 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_discarded.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | false 5 | false 6 | false 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_object.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | false 5 | false 6 | true 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_string.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | false 5 | false 6 | false 7 | false 8 | true 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_structured.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | false 5 | false 6 | true 7 | true 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__parent_pointer.output: -------------------------------------------------------------------------------- 1 | parent of "" is "" 2 | parent of "/foo" is "" 3 | parent of "/foo/0" is "/foo" 4 | -------------------------------------------------------------------------------- /docs/examples/out_of_range.output: -------------------------------------------------------------------------------- 1 | message: [json.exception.out_of_range.401] array index 4 is out of range 2 | exception id: 401 3 | -------------------------------------------------------------------------------- /docs/examples/swap__object_t.output: -------------------------------------------------------------------------------- 1 | value = {"translation":{"cow":"Kuh","dog":"Hund"}} 2 | object = {"one":"eins","two":"zwei"} 3 | -------------------------------------------------------------------------------- /docs/examples/type_error.output: -------------------------------------------------------------------------------- 1 | message: [json.exception.type_error.308] cannot use push_back() with string 2 | exception id: 308 3 | -------------------------------------------------------------------------------- /tests/reports/2016-08-29-fuzz/fuzz.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-08-29-fuzz/fuzz.tiff -------------------------------------------------------------------------------- /tests/reports/2016-10-02-fuzz/fuzz.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-10-02-fuzz/fuzz.tiff -------------------------------------------------------------------------------- /docs/examples/diagnostics_extended.output: -------------------------------------------------------------------------------- 1 | [json.exception.type_error.302] (/address/housenumber) type must be number, but is string 2 | -------------------------------------------------------------------------------- /docs/examples/emplace.output: -------------------------------------------------------------------------------- 1 | {"one":1,"two":2} 2 | null 3 | {"one":1,"three":3,"two":2} 4 | 3 true 5 | {"A":"a","B":"b"} 6 | "b" false 7 | -------------------------------------------------------------------------------- /docs/examples/get_ref.output: -------------------------------------------------------------------------------- 1 | 17 17 2 | [json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number 3 | -------------------------------------------------------------------------------- /docs/examples/is_number_float.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | false 5 | true 6 | false 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_number_integer.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | true 4 | true 5 | false 6 | false 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/is_number_unsigned.output: -------------------------------------------------------------------------------- 1 | false 2 | false 3 | false 4 | true 5 | false 6 | false 7 | false 8 | false 9 | false 10 | -------------------------------------------------------------------------------- /docs/examples/push_back__initializer_list.output: -------------------------------------------------------------------------------- 1 | {"one":1,"two":2} 2 | null 3 | {"four":4,"one":1,"three":3,"two":2} 4 | [["five",5]] 5 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/images/callback_events.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/mkdocs/docs/images/callback_events.png -------------------------------------------------------------------------------- /tests/reports/2016-08-29-fuzz/high_freq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-08-29-fuzz/high_freq.png -------------------------------------------------------------------------------- /tests/reports/2016-08-29-fuzz/low_freq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-08-29-fuzz/low_freq.png -------------------------------------------------------------------------------- /tests/reports/2016-10-02-fuzz/high_freq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-10-02-fuzz/high_freq.png -------------------------------------------------------------------------------- /tests/reports/2016-10-02-fuzz/low_freq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-10-02-fuzz/low_freq.png -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/swap-cmp.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SwapCmpTest -seed=1 -runs=10000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /docs/examples/at__keytype_const.c++17.output: -------------------------------------------------------------------------------- 1 | "il brutto" 2 | [json.exception.type_error.304] cannot use at() with string 3 | out of range 4 | -------------------------------------------------------------------------------- /docs/examples/back.output: -------------------------------------------------------------------------------- 1 | true 2 | 17 3 | 23.42 4 | 2 5 | 16 6 | "Hello, world" 7 | [json.exception.invalid_iterator.214] cannot get value 8 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator__equal.output: -------------------------------------------------------------------------------- 1 | "" == "": true 2 | "" == "": true 3 | "" == "/foo": false 4 | "/foo" == "/foo": true 5 | -------------------------------------------------------------------------------- /docs/examples/object.output: -------------------------------------------------------------------------------- 1 | {} 2 | {} 3 | {"one":1,"two":2} 4 | [json.exception.type_error.301] cannot create object from initializer list 5 | -------------------------------------------------------------------------------- /docs/examples/push_back__object_t__value.output: -------------------------------------------------------------------------------- 1 | {"one":1,"two":2} 2 | null 3 | {"four":4,"one":1,"three":3,"two":2} 4 | {"A":"a","B":"b"} 5 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/images/json_syntax_number.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/docs/mkdocs/docs/images/json_syntax_number.png -------------------------------------------------------------------------------- /tests/reports/2016-08-29-fuzz/exec_speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-08-29-fuzz/exec_speed.png -------------------------------------------------------------------------------- /tests/reports/2016-10-02-fuzz/exec_speed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-10-02-fuzz/exec_speed.png -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/simple-cmp.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SimpleCmpTest -seed=1 -runs=100000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /docs/examples/at__object_t_key_type_const.output: -------------------------------------------------------------------------------- 1 | "il brutto" 2 | [json.exception.type_error.304] cannot use at() with string 3 | out of range 4 | -------------------------------------------------------------------------------- /docs/examples/basic_json__list_init_t.output: -------------------------------------------------------------------------------- 1 | {} 2 | {"one":1,"two":2} 3 | [1,2,3,4] 4 | {"one":[1],"two":[1,2]} 5 | [[[1],"one"],[[1,2],"two"]] 6 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator__notequal.output: -------------------------------------------------------------------------------- 1 | "" != "": false 2 | "" != "": false 3 | "" != "/foo": true 4 | "/foo" != "/foo": false 5 | -------------------------------------------------------------------------------- /docs/examples/object_comparator_t.output: -------------------------------------------------------------------------------- 1 | json::object_comparator_t("one", "two") = true 2 | json::object_comparator_t("three", "four") = false 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/repeated-bytes.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: LLVMFuzzer-RepeatedBytesTest -seed=1 -runs=1000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /docs/examples/contains__keytype.c++17.output: -------------------------------------------------------------------------------- 1 | j_object contains 'key': true 2 | j_object contains 'another': false 3 | j_array contains 'key': false 4 | -------------------------------------------------------------------------------- /docs/examples/invalid_iterator.output: -------------------------------------------------------------------------------- 1 | message: [json.exception.invalid_iterator.207] cannot use key() for non-object iterators 2 | exception id: 207 3 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/css/custom.css: -------------------------------------------------------------------------------- 1 | /* disable ligatures in code and preformatted blocks */ 2 | code, pre { 3 | font-variant-ligatures: none; 4 | } 5 | -------------------------------------------------------------------------------- /docs/examples/contains__object_t_key_type.output: -------------------------------------------------------------------------------- 1 | j_object contains 'key': true 2 | j_object contains 'another': false 3 | j_array contains 'key': false 4 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_intrusive_only_serialize_macro.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | -------------------------------------------------------------------------------- /docs/examples/operator__equal.output: -------------------------------------------------------------------------------- 1 | [1,2,3] == [1,2,4] false 2 | {"A":"a","B":"b"} == {"A":"a","B":"b"} true 3 | 17 == 17.0 true 4 | "foo" == "bar" false 5 | -------------------------------------------------------------------------------- /docs/examples/basic_json__InputIt_InputIt.output: -------------------------------------------------------------------------------- 1 | ["bravo","charly"] 2 | 42 3 | {"one":"eins"} 4 | [json.exception.invalid_iterator.204] iterators out of range 5 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_intrusive_only_serialize_explicit.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_non_intrusive_only_serialize_macro.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | -------------------------------------------------------------------------------- /docs/examples/operator__notequal.output: -------------------------------------------------------------------------------- 1 | [1,2,3] != [1,2,4] true 2 | {"A":"a","B":"b"} != {"A":"a","B":"b"} false 3 | 17 != 17.0 false 4 | "foo" != "bar" true 5 | -------------------------------------------------------------------------------- /cmake/pkg-config.pc.in: -------------------------------------------------------------------------------- 1 | Name: ${PROJECT_NAME} 2 | Description: JSON for Modern C++ 3 | Version: ${PROJECT_VERSION} 4 | Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR} 5 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_non_intrusive_only_serialize_explicit.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_serialize_enum.output: -------------------------------------------------------------------------------- 1 | ns::TS_STOPPED -> "stopped", ns::Color::red -> "red" 2 | "running" -> 1, "blue" -> 2 3 | 3.14 -> -1, 3.14 -> 3 4 | -------------------------------------------------------------------------------- /docs/examples/to_bson.output: -------------------------------------------------------------------------------- 1 | 0x1b 0x00 0x00 0x00 0x08 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0x00 0x01 0x10 0x73 0x63 0x68 0x65 0x6d 0x61 0x00 0x00 0x00 0x00 0x00 0x00 2 | -------------------------------------------------------------------------------- /docs/examples/operator__greater.output: -------------------------------------------------------------------------------- 1 | [1,2,3] > [1,2,4] false 2 | {"A":"a","B":"b"} > {"A":"a","B":"b"} false 3 | 17 > 17.0000000000001 false 4 | "foo" > "bar" true 5 | -------------------------------------------------------------------------------- /docs/examples/operator__less.output: -------------------------------------------------------------------------------- 1 | [1,2,3] == [1,2,4] true 2 | {"A":"a","B":"b"} == {"A":"a","B":"b"} false 3 | 17 == 17.0000000000001 true 4 | "foo" == "bar" false 5 | -------------------------------------------------------------------------------- /docs/examples/operator__lessequal.output: -------------------------------------------------------------------------------- 1 | [1,2,3] <= [1,2,4] true 2 | {"A":"a","B":"b"} <= {"A":"a","B":"b"} true 3 | 17 <= 17.0000000000001 true 4 | "foo" <= "bar" false 5 | -------------------------------------------------------------------------------- /docs/examples/items.output: -------------------------------------------------------------------------------- 1 | key: one, value: 1 2 | key: two, value: 2 3 | key: 0, value: 1 4 | key: 1, value: 2 5 | key: 2, value: 4 6 | key: 3, value: 8 7 | key: 4, value: 16 8 | -------------------------------------------------------------------------------- /docs/examples/operator__greaterequal.output: -------------------------------------------------------------------------------- 1 | [1,2,3] >= [1,2,4] false 2 | {"A":"a","B":"b"} >= {"A":"a","B":"b"} true 3 | 17 >= 17.0000000000001 false 4 | "foo" >= "bar" true 5 | -------------------------------------------------------------------------------- /docs/examples/operator_spaceship__scalartype.c++20.output: -------------------------------------------------------------------------------- 1 | false <=> true := less 2 | 17 <=> 17.000000 := equivalent 3 | 17 <=> nan := unordered 4 | "17" <=> 17 := greater 5 | -------------------------------------------------------------------------------- /docs/examples/other_error.output: -------------------------------------------------------------------------------- 1 | message: [json.exception.other_error.501] unsuccessful: {"op":"test","path":"/best_biscuit/name","value":"Choco Leibniz"} 2 | exception id: 501 3 | -------------------------------------------------------------------------------- /docs/examples/patch.output: -------------------------------------------------------------------------------- 1 | { 2 | "baz": "qux", 3 | "foo": "bar" 4 | } 5 | 6 | { 7 | "baz": "boo", 8 | "hello": [ 9 | "world" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-cmp.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SimpleCmpTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /docs/examples/at__size_type_const.output: -------------------------------------------------------------------------------- 1 | "third" 2 | [json.exception.type_error.304] cannot use at() with string 3 | [json.exception.out_of_range.401] array index 5 is out of range 4 | -------------------------------------------------------------------------------- /docs/examples/insert__range_object.output: -------------------------------------------------------------------------------- 1 | {"one":"eins","two":"zwei"} 2 | {"eleven":"elf","seventeen":"siebzehn"} 3 | {"eleven":"elf","one":"eins","seventeen":"siebzehn","two":"zwei"} 4 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__to_string.output: -------------------------------------------------------------------------------- 1 | "" 2 | "/foo" 3 | "/foo/0" 4 | "/" 5 | "/a~1b" 6 | "/c%d" 7 | "/e^f" 8 | "/g|h" 9 | "/i\j" 10 | "/k"l" 11 | "/ " 12 | "/m~0n" 13 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/unit/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@" 2 | lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/unit/lit.cfg") 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-cmp2.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SimpleHashTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-div.test: -------------------------------------------------------------------------------- 1 | CHECK: AddressSanitizer: FPE 2 | RUN: not LLVMFuzzer-DivTest -seed=1 -use_value_profile=1 -runs=10000000 2>&1 | FileCheck %s 3 | 4 | -------------------------------------------------------------------------------- /docs/examples/operator__equal__nullptr_t.output: -------------------------------------------------------------------------------- 1 | [1,2,3] == nullptr false 2 | {"A":"a","B":"b"} == nullptr false 3 | 17 == nullptr false 4 | "foo" == nullptr false 5 | null == nullptr true 6 | -------------------------------------------------------------------------------- /docs/examples/operator__notequal__nullptr_t.output: -------------------------------------------------------------------------------- 1 | [1,2,3] != nullptr true 2 | {"A":"a","B":"b"} != nullptr true 3 | 17 != nullptr true 4 | "foo" != nullptr true 5 | null != nullptr false 6 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-cmp3.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-AbsNegAndConstantTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-cmp4.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-AbsNegAndConstant64Test -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__byte_container_with_subtype.output: -------------------------------------------------------------------------------- 1 | {"bytes":[],"subtype":null} 2 | {"bytes":[202,254,186,190],"subtype":null} 3 | {"bytes":[202,254,186,190],"subtype":42} 4 | -------------------------------------------------------------------------------- /docs/examples/operator_array__json_pointer.output: -------------------------------------------------------------------------------- 1 | 1 2 | "foo" 3 | [1,2] 4 | 2 5 | "bar" 6 | {"array":[1,2],"boolean":true,"number":1,"string":"bar"} 7 | [1,21,null,null,44] 8 | [1,21,null,null,44,55] 9 | -------------------------------------------------------------------------------- /tests/reports/2016-09-09-nativejson_benchmark/conformance_overall_Result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-09-09-nativejson_benchmark/conformance_overall_Result.png -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/caller-callee.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-CallerCalleeTest -use_value_profile=1 -cross_over=0 -max_len=6 -seed=1 -runs=10000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-seed.test: -------------------------------------------------------------------------------- 1 | RUN: LLVMFuzzer-SimpleCmpTest -seed=-1 -runs=0 2>&1 | FileCheck %s --check-prefix=CHECK_SEED_MINUS_ONE 2 | CHECK_SEED_MINUS_ONE: Seed: 4294967295 3 | 4 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-mem.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SingleMemcmpTest -seed=1 -use_cmp=0 -use_memcmp=0 -use_value_profile=1 -runs=10000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-set.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-FourIndependentBranchesTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=100000000 2>&1 | FileCheck %s 3 | 4 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-strcmp.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SingleStrcmpTest -seed=1 -use_cmp=0 -use_memcmp=0 -use_value_profile=1 -runs=10000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-strncmp.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SingleStrncmpTest -seed=1 -use_cmp=0 -use_memcmp=0 -use_value_profile=1 -runs=10000000 2>&1 | FileCheck %s 3 | -------------------------------------------------------------------------------- /docs/examples/error_handler_t.output: -------------------------------------------------------------------------------- 1 | [json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9 2 | string with replaced invalid characters: "ä�ü" 3 | string with ignored invalid characters: "äü" 4 | -------------------------------------------------------------------------------- /docs/examples/json_base_class_t.output: -------------------------------------------------------------------------------- 1 | / - metadata = 42 -> {"null":null,"object":{"uint":1}} 2 | /null - metadata = 42 -> null 3 | /object - metadata = 21 -> {"uint":1} 4 | /object/uint - metadata = 42 -> 1 5 | -------------------------------------------------------------------------------- /docs/examples/patch_inplace.output: -------------------------------------------------------------------------------- 1 | Before 2 | { 3 | "baz": "qux", 4 | "foo": "bar" 5 | } 6 | 7 | After 8 | { 9 | "baz": "boo", 10 | "hello": [ 11 | "world" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /docs/examples/at__size_type.output: -------------------------------------------------------------------------------- 1 | "third" 2 | ["first","second","third","fourth"] 3 | [json.exception.type_error.304] cannot use at() with string 4 | [json.exception.out_of_range.401] array index 5 is out of range 5 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__clear_subtype.output: -------------------------------------------------------------------------------- 1 | before calling clear_subtype(): {"bytes":[202,254,186,190],"subtype":42} 2 | after calling clear_subtype(): {"bytes":[202,254,186,190],"subtype":null} 3 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__set_subtype.output: -------------------------------------------------------------------------------- 1 | before calling set_subtype(42): {"bytes":[202,254,186,190],"subtype":null} 2 | after calling set_subtype(42): {"bytes":[202,254,186,190],"subtype":42} 3 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-load.test: -------------------------------------------------------------------------------- 1 | CHECK: AddressSanitizer: global-buffer-overflow 2 | RUN: not LLVMFuzzer-LoadTest -seed=1 -use_cmp=0 -use_value_profile=1 -runs=10000000 2>&1 | FileCheck %s 3 | 4 | -------------------------------------------------------------------------------- /docs/examples/operator_spaceship__const_reference.c++20.output: -------------------------------------------------------------------------------- 1 | [1,2,3] <=> [1,2,4] := less 2 | {"A":"a","B":"b"} <=> {"A":"a","B":"b"} := equivalent 3 | "foo" <=> 17 := greater 4 | "foo" <=> := unordered 5 | -------------------------------------------------------------------------------- /docs/examples/ordered_map.output: -------------------------------------------------------------------------------- 1 | m_ordered = { one:eins two:zwei three:drei } 2 | m_std = { one:eins three:drei two:zwei } 3 | m_ordered = { two:zwei three:drei one:eins } 4 | m_std = { one:eins three:drei two:zwei } 5 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_intrusive_explicit.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | deserialization failed: [json.exception.out_of_range.403] key 'age' not found 3 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_intrusive_macro.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | deserialization failed: [json.exception.out_of_range.403] key 'age' not found 3 | -------------------------------------------------------------------------------- /docs/examples/type_name.output: -------------------------------------------------------------------------------- 1 | null is a null 2 | true is a boolean 3 | -17 is a number 4 | 42 is a number 5 | 23.42 is a number 6 | {"one":1,"two":2} is an object 7 | [1,2,4,8,16] is an array 8 | "Hello, world" is a string 9 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_non_intrusive_explicit.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | deserialization failed: [json.exception.out_of_range.403] key 'age' not found 3 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_non_intrusive_macro.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | deserialization failed: [json.exception.out_of_range.403] key 'age' not found 3 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/conan/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | std::cout << json::meta() << std::endl; 9 | } 10 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/vcpkg/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | std::cout << json::meta() << std::endl; 9 | } 10 | -------------------------------------------------------------------------------- /tools/amalgamate/config_json.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "JSON for Modern C++", 3 | "target": "single_include/nlohmann/json.hpp", 4 | "sources": [ 5 | "include/nlohmann/json.hpp" 6 | ], 7 | "include_paths": ["include"] 8 | } 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask a question 4 | url: https://github.com/nlohmann/json/discussions 5 | about: Ask questions and discuss with other community members 6 | -------------------------------------------------------------------------------- /docs/examples/get_to.output: -------------------------------------------------------------------------------- 1 | 1 2 | 42 42 3 | 17.23 17 4 | Hello, world! 5 | 1 2 3 4 5 6 | 7 | string: "Hello, world!" 8 | number: {"floating-point":17.23,"integer":42} 9 | null: null 10 | boolean: true 11 | array: [1,2,3,4,5] 12 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_intrusive_with_default_explicit.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | roundtrip: {"address":"742 Evergreen Terrace","age":-1,"name":"Maggie Simpson"} 3 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_intrusive_with_default_macro.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | roundtrip: {"address":"742 Evergreen Terrace","age":-1,"name":"Maggie Simpson"} 3 | -------------------------------------------------------------------------------- /docs/examples/operator_deserialize.output: -------------------------------------------------------------------------------- 1 | { 2 | "array": [ 3 | 1, 4 | 2, 5 | 3, 6 | 4, 7 | 5 8 | ], 9 | "boolean": false, 10 | "null": null, 11 | "number": 23, 12 | "string": "Hello, world!" 13 | } 14 | -------------------------------------------------------------------------------- /tools/amalgamate/config_json_fwd.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "JSON for Modern C++", 3 | "target": "single_include/nlohmann/json_fwd.hpp", 4 | "sources": [ 5 | "include/nlohmann/json_fwd.hpp" 6 | ], 7 | "include_paths": ["include"] 8 | } 9 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_non_intrusive_with_default_explicit.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | roundtrip: {"address":"742 Evergreen Terrace","age":-1,"name":"Maggie Simpson"} 3 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_non_intrusive_with_default_macro.output: -------------------------------------------------------------------------------- 1 | serialization: {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"} 2 | roundtrip: {"address":"742 Evergreen Terrace","age":-1,"name":"Maggie Simpson"} 3 | -------------------------------------------------------------------------------- /docs/examples/parse_error.output: -------------------------------------------------------------------------------- 1 | message: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal 2 | exception id: 101 3 | byte position of error: 8 4 | -------------------------------------------------------------------------------- /docs/examples/cbor_tag_handler_t.output: -------------------------------------------------------------------------------- 1 | [json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0xD8 2 | {"bytes":[202,254,186,190],"subtype":null} 3 | {"bytes":[202,254,186,190],"subtype":66} 4 | -------------------------------------------------------------------------------- /docs/examples/json_lines.output: -------------------------------------------------------------------------------- 1 | {"name":"Gilbert","wins":[["straight","7♣"],["one pair","10♥"]]} 2 | {"name":"Alexa","wins":[["two pair","4♠"],["two pair","9♠"]]} 3 | {"name":"May","wins":[]} 4 | {"name":"Deloise","wins":[["three of a kind","5♣"]]} 5 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-custommutator.test: -------------------------------------------------------------------------------- 1 | RUN: not LLVMFuzzer-CustomMutatorTest 2>&1 | FileCheck %s --check-prefix=LLVMFuzzerCustomMutator 2 | LLVMFuzzerCustomMutator: In LLVMFuzzerCustomMutator 3 | LLVMFuzzerCustomMutator: BINGO 4 | 5 | -------------------------------------------------------------------------------- /docs/examples/at__keytype.c++17.output: -------------------------------------------------------------------------------- 1 | "il brutto" 2 | {"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"} 3 | [json.exception.type_error.304] cannot use at() with string 4 | [json.exception.out_of_range.403] key 'the fast' not found 5 | -------------------------------------------------------------------------------- /docs/examples/get__ValueType_const.output: -------------------------------------------------------------------------------- 1 | 1 2 | 42 42 3 | 17.23 17 4 | Hello, world! 5 | 1 2 3 4 5 6 | 7 | string: "Hello, world!" 8 | number: {"floating-point":17.23,"integer":42} 9 | null: null 10 | boolean: true 11 | array: [1,2,3,4,5] 12 | -------------------------------------------------------------------------------- /docs/examples/at__object_t_key_type.output: -------------------------------------------------------------------------------- 1 | "il brutto" 2 | {"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"} 3 | [json.exception.type_error.304] cannot use at() with string 4 | [json.exception.out_of_range.403] key 'the fast' not found 5 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator__equal_stringtype.output: -------------------------------------------------------------------------------- 1 | "" == "": true 2 | "" == "": true 3 | "/foo" == "/foo": true 4 | "bar" == "/foo": [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'bar' 5 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator__notequal_stringtype.output: -------------------------------------------------------------------------------- 1 | "" != "": false 2 | "" != "": false 3 | "/foo" != "/foo": false 4 | "bar" != "/foo": [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'bar' 5 | -------------------------------------------------------------------------------- /docs/examples/meta.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // call meta() 10 | std::cout << std::setw(4) << json::meta() << '\n'; 11 | } 12 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/features/parsing/index.md: -------------------------------------------------------------------------------- 1 | # Parsing 2 | 3 | !!! note 4 | 5 | This page is under construction. 6 | 7 | ## Input 8 | 9 | ## SAX vs. DOM parsing 10 | 11 | ## Exceptions 12 | 13 | See [parsing and exceptions](parse_exceptions.md). 14 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::setw(4) << json::meta() << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-ubsan.test: -------------------------------------------------------------------------------- 1 | RUN: not LLVMFuzzer-SignedIntOverflowTest-Ubsan 2>&1 | FileCheck %s 2 | CHECK: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int' 3 | CHECK: Test unit written to ./crash- 4 | 5 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-printcovpcs.test: -------------------------------------------------------------------------------- 1 | RUN: LLVMFuzzer-SimpleTest -print_pcs=1 -seed=1 2>&1 | FileCheck %s --check-prefix=PCS 2 | PCS-NOT: NEW_PC 3 | PCS:INITED 4 | PCS:NEW_PC: {{0x[a-f0-9]+}} 5 | PCS:NEW_PC: {{0x[a-f0-9]+}} 6 | PCS:NEW 7 | PCS:BINGO 8 | 9 | -------------------------------------------------------------------------------- /docs/examples/operator_ltlt__basic_json.output: -------------------------------------------------------------------------------- 1 | {"one":1,"two":2} 2 | 3 | [1,2,4,8,16] 4 | 5 | { 6 | "one": 1, 7 | "two": 2 8 | } 9 | 10 | [ 11 | 1, 12 | 2, 13 | 4, 14 | 8, 15 | 16 16 | ] 17 | 18 | { 19 | "one": 1, 20 | "two": 2 21 | } 22 | 23 | -------------------------------------------------------------------------------- /docs/examples/std_hash.output: -------------------------------------------------------------------------------- 1 | hash(null) = 2654435769 2 | hash(false) = 2654436030 3 | hash(0) = 2654436095 4 | hash(0U) = 2654436156 5 | hash("") = 6142509191626859748 6 | hash({}) = 2654435832 7 | hash([]) = 2654435899 8 | hash({"hello": "world"}) = 4469488738203676328 9 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@" 2 | config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" 3 | config.has_lsan = True if @HAS_LSAN@ == 1 else False 4 | lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg") 5 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/standalone.test: -------------------------------------------------------------------------------- 1 | RUN: LLVMFuzzer-StandaloneInitializeTest %S/hi.txt %S/dict1.txt 2>&1 | FileCheck %s 2 | CHECK: StandaloneFuzzTargetMain: running 2 inputs 3 | CHECK: Done: {{.*}}hi.txt: (3 bytes) 4 | CHECK: Done: {{.*}}dict1.txt: (61 bytes) 5 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/unit/lit.cfg: -------------------------------------------------------------------------------- 1 | import lit.formats 2 | 3 | config.name = "LLVMFuzzer-Unittest" 4 | print config.test_exec_root 5 | config.test_format = lit.formats.GoogleTest(".", "Unittest") 6 | config.suffixes = [] 7 | config.test_source_root = config.test_exec_root 8 | -------------------------------------------------------------------------------- /docs/examples/boolean_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /docs/examples/merge_patch.output: -------------------------------------------------------------------------------- 1 | { 2 | "author": { 3 | "givenName": "John" 4 | }, 5 | "content": "This will be unchanged", 6 | "phoneNumber": "+01-123-456-7890", 7 | "tags": [ 8 | "example" 9 | ], 10 | "title": "Hello!" 11 | } 12 | -------------------------------------------------------------------------------- /tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_1._Parse_Time_(ms).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_1._Parse_Time_(ms).png -------------------------------------------------------------------------------- /tools/generate_natvis/README.md: -------------------------------------------------------------------------------- 1 | generate_natvis.py 2 | ================== 3 | 4 | Generate the Natvis debugger visualization file for all supported namespace combinations. 5 | 6 | ## Usage 7 | 8 | ``` 9 | ./generate_natvis.py --version X.Y.Z output_directory/ 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/examples/array_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same, json::array_t>::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /docs/examples/string_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_1._Parse_Memory_(byte).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_1._Parse_Memory_(byte).png -------------------------------------------------------------------------------- /tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_2._Stringify_Time_(ms).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_2._Stringify_Time_(ms).png -------------------------------------------------------------------------------- /tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_3._Prettify_Time_(ms).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_3._Prettify_Time_(ms).png -------------------------------------------------------------------------------- /docs/docset/docset.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "JSON for Modern C++", 3 | "version": "3.11.3", 4 | "archive": "JSON_for_Modern_C++.tgz", 5 | "author": { 6 | "name": "Niels Lohmann", 7 | "link": "https://twitter.com/nlohmann" 8 | }, 9 | "aliases": ["nlohmann/json"] 10 | } 11 | -------------------------------------------------------------------------------- /docs/examples/number_float_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/vcpkg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(json_example) 2 | cmake_minimum_required(VERSION 2.8.12) 3 | 4 | find_package(nlohmann_json CONFIG REQUIRED) 5 | 6 | add_executable(json_example example.cpp) 7 | target_link_libraries(json_example PRIVATE nlohmann_json::nlohmann_json) 8 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LIBFUZZER_SRC_DIR=$(dirname $0) 3 | for f in $LIBFUZZER_SRC_DIR/*.cpp; do 4 | clang -g -O2 -fno-omit-frame-pointer -std=c++11 $f -c & 5 | done 6 | wait 7 | rm -f libFuzzer.a 8 | ar ru libFuzzer.a Fuzzer*.o 9 | rm -f Fuzzer*.o 10 | 11 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/value-profile-switch.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | RUN: not LLVMFuzzer-SwitchTest -use_cmp=0 -use_value_profile=1 -runs=100000000 -seed=1 2>&1 | FileCheck %s 3 | RUN: not LLVMFuzzer-Switch2Test -use_cmp=0 -use_value_profile=1 -runs=100000000 -seed=1 2>&1 | FileCheck %s 4 | -------------------------------------------------------------------------------- /docs/examples/number_integer_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /docs/examples/object_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same, json::object_t>::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_7._Code_size_FileSize_(byte).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Parker8287/json/HEAD/tests/reports/2016-09-09-nativejson_benchmark/performance_Corei7-4980HQ@2.80GHz_mac64_clang7.0_7._Code_size_FileSize_(byte).png -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # JSON for Modern C++ was originally written by Niels Lohmann. 2 | # Since 2013, over 250 contributors have helped to improve the library. 3 | # This CODEOWNERS file is only to make sure that @nlohmann is requested 4 | # for a code review in case of a pull request. 5 | 6 | * @nlohmann 7 | -------------------------------------------------------------------------------- /docs/examples/number_unsigned_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /docs/examples/parse__allow_exceptions.output: -------------------------------------------------------------------------------- 1 | [json.exception.parse_error.101] parse error at line 4, column 0: syntax error while parsing value - invalid string: control character U+000A (LF) must be escaped to \u000A or \n; last read: '"value without closing quotes' 2 | the input is invalid JSON 3 | -------------------------------------------------------------------------------- /docs/examples/flatten.output: -------------------------------------------------------------------------------- 1 | { 2 | "/answer/everything": 42, 3 | "/happy": true, 4 | "/list/0": 1, 5 | "/list/1": 0, 6 | "/list/2": 2, 7 | "/name": "Niels", 8 | "/nothing": null, 9 | "/object/currency": "USD", 10 | "/object/value": 42.99, 11 | "/pi": 3.141 12 | } 13 | -------------------------------------------------------------------------------- /.reuse/README.md: -------------------------------------------------------------------------------- 1 | # REUSE Software 2 | 3 | This directory contains supporting files to make the project compliant with the REUSE specification. 4 | 5 | The root `Makefile` contains a target `reuse` that updates copyright headers and checks for compliance. 6 | 7 | See for more information. 8 | -------------------------------------------------------------------------------- /docs/examples/update.output: -------------------------------------------------------------------------------- 1 | { 2 | "color": "blue", 3 | "names": { 4 | "en": "plane" 5 | }, 6 | "price": 17.99, 7 | "speed": 100 8 | } 9 | { 10 | "color": "blue", 11 | "names": { 12 | "de": "Flugzeug", 13 | "en": "plane" 14 | }, 15 | "price": 17.99, 16 | "speed": 100 17 | } 18 | -------------------------------------------------------------------------------- /tests/cmake_import_minver/project/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1...3.14) 2 | 3 | project(DummyImportMinVer CXX) 4 | 5 | find_package(nlohmann_json 3.2.0 REQUIRED) 6 | 7 | add_executable(with_namespace_target main.cpp) 8 | target_link_libraries(with_namespace_target nlohmann_json::nlohmann_json) 9 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/DSOTestExtra.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Source code for a simple DSO. 5 | 6 | int DSOTestExtra(int a) { 7 | if (a < 452345) 8 | return 0; 9 | return 1; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /docs/examples/operator__ValueType.output: -------------------------------------------------------------------------------- 1 | 1 2 | 42 42 3 | 17.23 17 4 | Hello, world! 5 | 1 2 3 4 5 6 | 7 | string: "Hello, world!" 8 | number: {"floating-point":17.23,"integer":42} 9 | null: null 10 | boolean: true 11 | array: [1,2,3,4,5] 12 | [json.exception.type_error.302] type must be boolean, but is string 13 | -------------------------------------------------------------------------------- /docs/examples/ordered_json.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using ordered_json = nlohmann::ordered_json; 5 | 6 | int main() 7 | { 8 | ordered_json j; 9 | j["one"] = 1; 10 | j["two"] = 2; 11 | j["three"] = 3; 12 | 13 | std::cout << j.dump(2) << '\n'; 14 | } 15 | -------------------------------------------------------------------------------- /docs/examples/update__range.output: -------------------------------------------------------------------------------- 1 | { 2 | "color": "blue", 3 | "names": { 4 | "en": "plane" 5 | }, 6 | "price": 17.99, 7 | "speed": 100 8 | } 9 | { 10 | "color": "blue", 11 | "names": { 12 | "de": "Flugzeug", 13 | "en": "plane" 14 | }, 15 | "price": 17.99, 16 | "speed": 100 17 | } 18 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/DSO1.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Source code for a simple DSO. 5 | 6 | int DSO1(int a) { 7 | if (a < 123456) 8 | return 0; 9 | return 1; 10 | } 11 | 12 | void Uncovered1() { } 13 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/DSO2.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Source code for a simple DSO. 5 | 6 | int DSO2(int a) { 7 | if (a < 3598235) 8 | return 0; 9 | return 1; 10 | } 11 | 12 | void Uncovered2() {} 13 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-oom-with-profile.test: -------------------------------------------------------------------------------- 1 | REQUIRES: linux 2 | RUN: not LLVMFuzzer-OutOfMemoryTest -rss_limit_mb=300 2>&1 | FileCheck %s 3 | CHECK: ERROR: libFuzzer: out-of-memory (used: {{.*}}; limit: 300Mb) 4 | CHECK: Live Heap Allocations 5 | CHECK: Test unit written to ./oom- 6 | SUMMARY: libFuzzer: out-of-memory 7 | -------------------------------------------------------------------------------- /docs/examples/binary_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | std::cout << std::boolalpha << std::is_same>, json::binary_t>::value << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /docs/examples/operator_array__keytype.c++17.output: -------------------------------------------------------------------------------- 1 | 2 2 | 3 | { 4 | "one": 1, 5 | "three": 3, 6 | "two": 2 7 | } 8 | 9 | { 10 | "five": { 11 | "really": { 12 | "nested": true 13 | } 14 | }, 15 | "four": null, 16 | "one": 1, 17 | "three": 3, 18 | "two": 2 19 | } 20 | -------------------------------------------------------------------------------- /docs/examples/operator_array__object_t_key_type.output: -------------------------------------------------------------------------------- 1 | 2 2 | 3 | { 4 | "one": 1, 5 | "three": 3, 6 | "two": 2 7 | } 8 | 9 | { 10 | "five": { 11 | "really": { 12 | "nested": true 13 | } 14 | }, 15 | "four": null, 16 | "one": 1, 17 | "three": 3, 18 | "two": 2 19 | } 20 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/conan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(json_example) 2 | cmake_minimum_required(VERSION 2.8.12) 3 | add_definitions("-std=c++11") 4 | 5 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 6 | conan_basic_setup() 7 | 8 | add_executable(json_example example.cpp) 9 | target_link_libraries(json_example ${CONAN_LIBS}) 10 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-dict.test: -------------------------------------------------------------------------------- 1 | CHECK: BINGO 2 | Done1000000: Done 1000000 runs in 3 | 4 | RUN: not LLVMFuzzer-SimpleDictionaryTest -dict=%S/dict1.txt -seed=1 -runs=1000003 2>&1 | FileCheck %s 5 | RUN: LLVMFuzzer-SimpleDictionaryTest -seed=1 -runs=1000000 2>&1 | FileCheck %s --check-prefix=Done1000000 6 | 7 | -------------------------------------------------------------------------------- /docs/examples/operator_ltlt__json_pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON poiner 9 | json::json_pointer ptr("/foo/bar/baz"); 10 | 11 | // write string representation to stream 12 | std::cout << ptr << std::endl; 13 | } 14 | -------------------------------------------------------------------------------- /docs/examples/json_pointer.output: -------------------------------------------------------------------------------- 1 | [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo' 2 | [json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1' 3 | [json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1' 4 | -------------------------------------------------------------------------------- /docs/examples/operator_literal_json.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | using namespace nlohmann::literals; 7 | 8 | int main() 9 | { 10 | json j = R"( {"hello": "world", "answer": 42} )"_json; 11 | 12 | std::cout << std::setw(2) << j << '\n'; 13 | } 14 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/features/element_access/index.md: -------------------------------------------------------------------------------- 1 | # Element Access 2 | 3 | There are many ways elements in a JSON value can be accessed: 4 | 5 | - unchecked access via [`operator[]`](unchecked_access.md) 6 | - checked access via [`at`](checked_access.md) 7 | - access with default value via [`value`](default_value.md) 8 | - iterators 9 | - JSON pointers 10 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-segv.test: -------------------------------------------------------------------------------- 1 | RUN: ASAN_OPTIONS=handle_segv=0 not LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_OWN_SEGV_HANDLER 2 | LIBFUZZER_OWN_SEGV_HANDLER: == ERROR: libFuzzer: deadly signal 3 | LIBFUZZER_OWN_SEGV_HANDLER: SUMMARY: libFuzzer: deadly signal 4 | LIBFUZZER_OWN_SEGV_HANDLER: Test unit written to ./crash- 5 | 6 | -------------------------------------------------------------------------------- /docs/examples/erase__size_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON array 9 | json j_array = {0, 1, 2, 3, 4, 5}; 10 | 11 | // call erase() 12 | j_array.erase(2); 13 | 14 | // print values 15 | std::cout << j_array << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /docs/examples/unflatten.output: -------------------------------------------------------------------------------- 1 | { 2 | "answer": { 3 | "everything": 42 4 | }, 5 | "happy": true, 6 | "list": [ 7 | 1, 8 | 0, 9 | 2 10 | ], 11 | "name": "Niels", 12 | "nothing": null, 13 | "object": { 14 | "currency": "USD", 15 | "value": 42.99 16 | }, 17 | "pi": 3.141 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/operator_array__size_type_const.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON array 9 | const json array = {"first", "2nd", "third", "fourth"}; 10 | 11 | // output element at index 2 (third element) 12 | std::cout << array.at(2) << '\n'; 13 | } 14 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/EmptyTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | // 4 | // A fuzzer with empty target function. 5 | 6 | #include 7 | #include 8 | 9 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-runs.test: -------------------------------------------------------------------------------- 1 | RUN: mkdir -p %t 2 | RUN: echo abcd > %t/NthRunCrashTest.in 3 | RUN: LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in 4 | RUN: LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in -runs=10 5 | RUN: not LLVMFuzzer-NthRunCrashTest %t/NthRunCrashTest.in -runs=10000 2>&1 | FileCheck %s 6 | RUN: rm %t/NthRunCrashTest.in 7 | CHECK: BINGO 8 | 9 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/UninstrumentedTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // This test should not be instrumented. 5 | #include 6 | #include 7 | 8 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_namespace_no_version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 1 4 | #include 5 | 6 | // macro needed to output the NLOHMANN_JSON_NAMESPACE as string literal 7 | #define Q(x) #x 8 | #define QUOTE(x) Q(x) 9 | 10 | int main() 11 | { 12 | std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; 13 | } 14 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | std::cout << "JSON for Modern C++ version " 9 | << NLOHMANN_JSON_VERSION_MAJOR << "." 10 | << NLOHMANN_JSON_VERSION_MINOR << "." 11 | << NLOHMANN_JSON_VERSION_PATCH << std::endl; 12 | } 13 | -------------------------------------------------------------------------------- /tests/cuda_example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | project(json_cuda LANGUAGES CUDA) 3 | 4 | add_executable(json_cuda json_cuda.cu) 5 | target_include_directories(json_cuda PRIVATE ../../include) 6 | target_compile_features(json_cuda PUBLIC cuda_std_11) 7 | set_target_properties(json_cuda PROPERTIES 8 | CUDA_EXTENSIONS OFF 9 | CUDA_STANDARD_REQUIRED ON 10 | ) 11 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-threaded.test: -------------------------------------------------------------------------------- 1 | CHECK: Done 1000 runs in 2 | 3 | RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s 4 | RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s 5 | RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s 6 | RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s 7 | 8 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__string_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | json::json_pointer::string_t s = "This is a string."; 9 | 10 | std::cout << s << std::endl; 11 | 12 | std::cout << std::boolalpha << std::is_same::value << std::endl; 13 | } 14 | -------------------------------------------------------------------------------- /docs/examples/basic_json__copyassignment.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON values 9 | json a = 23; 10 | json b = 42; 11 | 12 | // copy-assign a to b 13 | b = a; 14 | 15 | // serialize the JSON arrays 16 | std::cout << a << '\n'; 17 | std::cout << b << '\n'; 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/basic_json__moveconstructor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON value 9 | json a = 23; 10 | 11 | // move contents of a to b 12 | json b(std::move(a)); 13 | 14 | // serialize the JSON arrays 15 | std::cout << a << '\n'; 16 | std::cout << b << '\n'; 17 | } 18 | -------------------------------------------------------------------------------- /docs/examples/basic_json__nullptr_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // implicitly create a JSON null value 9 | json j1; 10 | 11 | // explicitly create a JSON null value 12 | json j2(nullptr); 13 | 14 | // serialize the JSON null value 15 | std::cout << j1 << '\n' << j2 << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /docs/examples/operator_literal_json_pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | using namespace nlohmann::literals; 7 | 8 | int main() 9 | { 10 | json j = R"( {"hello": "world", "answer": 42} )"_json; 11 | auto val = j["/hello"_json_pointer]; 12 | 13 | std::cout << std::setw(2) << val << '\n'; 14 | } 15 | -------------------------------------------------------------------------------- /docs/examples/operator_array__object_t_key_type_const.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON object 9 | const json object = 10 | { 11 | {"one", 1}, {"two", 2}, {"three", 2.9} 12 | }; 13 | 14 | // output element with key "two" 15 | std::cout << object["two"] << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /docs/examples/default_object_comparator_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | std::cout << std::boolalpha 9 | << "one < two : " << json::default_object_comparator_t{}("one", "two") << "\n" 10 | << "three < four : " << json::default_object_comparator_t{}("three", "four") << std::endl; 11 | } 12 | -------------------------------------------------------------------------------- /.reuse/templates/json.jinja2: -------------------------------------------------------------------------------- 1 | __ _____ _____ _____ 2 | __| | __| | | | JSON for Modern C++ 3 | | | |__ | | | | | | version 3.11.3 4 | |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | 6 | {% for copyright_line in copyright_lines %} 7 | {{ copyright_line }} 8 | {% endfor %} 9 | {% for expression in spdx_expressions %} 10 | SPDX-License-Identifier: {{ expression }} 11 | {% endfor %} 12 | -------------------------------------------------------------------------------- /docs/examples/begin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to the first element 12 | json::iterator it = array.begin(); 13 | 14 | // serialize the element that the iterator points to 15 | std::cout << *it << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /tools/serve_header/serve_header.yml.example: -------------------------------------------------------------------------------- 1 | # all paths are relative to the project root 2 | 3 | # the root directory for the web server 4 | # root: . 5 | 6 | # configure SSL 7 | # https: 8 | # enabled: true 9 | # these filenames are listed in .gitignore 10 | # cert_file: localhost.pem 11 | # key_file: localhost-key.pem 12 | 13 | # address and port for the server to listen on 14 | # bind: null 15 | # port: 8443 16 | -------------------------------------------------------------------------------- /docs/examples/at__json_pointer_const.output: -------------------------------------------------------------------------------- 1 | 1 2 | "foo" 3 | [1,2] 4 | 2 5 | [json.exception.parse_error.109] parse error: array index 'one' is not a number 6 | [json.exception.out_of_range.401] array index 4 is out of range 7 | [json.exception.out_of_range.402] array index '-' (2) is out of range 8 | [json.exception.out_of_range.403] key 'foo' not found 9 | [json.exception.out_of_range.404] unresolved reference token 'foo' 10 | -------------------------------------------------------------------------------- /docs/examples/cbegin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | const json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to the first element 12 | json::const_iterator it = array.cbegin(); 13 | 14 | // serialize the element that the iterator points to 15 | std::cout << *it << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /docs/examples/rbegin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to the reverse-beginning 12 | json::reverse_iterator it = array.rbegin(); 13 | 14 | // serialize the element that the iterator points to 15 | std::cout << *it << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /tests/cmake_import/project/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1...3.14) 2 | 3 | project(DummyImport CXX) 4 | 5 | find_package(nlohmann_json REQUIRED) 6 | 7 | add_executable(with_namespace_target main.cpp) 8 | target_link_libraries(with_namespace_target nlohmann_json::nlohmann_json) 9 | 10 | add_executable(without_namespace_target main.cpp) 11 | target_link_libraries(without_namespace_target nlohmann_json) 12 | 13 | -------------------------------------------------------------------------------- /docs/examples/crbegin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to the reverse-beginning 12 | json::const_reverse_iterator it = array.crbegin(); 13 | 14 | // serialize the element that the iterator points to 15 | std::cout << *it << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /tests/cmake_target_include_directories/project/Bar.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include "Bar.hpp" 10 | 11 | class Bar; 12 | -------------------------------------------------------------------------------- /tests/cmake_target_include_directories/project/Foo.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include "Foo.hpp" 10 | 11 | class Foo; 12 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: "Pull Request Labeler" 2 | 3 | on: 4 | pull_request_target: 5 | types: [opened, synchronize] 6 | 7 | permissions: {} 8 | 9 | jobs: 10 | label: 11 | permissions: 12 | contents: read 13 | pull-requests: write 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: srvaroa/labeler@master 19 | env: 20 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 21 | -------------------------------------------------------------------------------- /.reuse/templates/json_support.jinja2: -------------------------------------------------------------------------------- 1 | __ _____ _____ _____ 2 | __| | __| | | | JSON for Modern C++ (supporting code) 3 | | | |__ | | | | | | version 3.11.3 4 | |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | 6 | {% for copyright_line in copyright_lines %} 7 | {{ copyright_line }} 8 | {% endfor %} 9 | {% for expression in spdx_expressions %} 10 | SPDX-License-Identifier: {{ expression }} 11 | {% endfor %} 12 | -------------------------------------------------------------------------------- /docs/examples/insert.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON array 9 | json v = {1, 2, 3, 4}; 10 | 11 | // insert number 10 before number 3 12 | auto new_pos = v.insert(v.begin() + 2, 10); 13 | 14 | // output new array and result of insert call 15 | std::cout << *new_pos << '\n'; 16 | std::cout << v << '\n'; 17 | } 18 | -------------------------------------------------------------------------------- /tests/src/unit.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 10 | #include "doctest_compatibility.h" 11 | -------------------------------------------------------------------------------- /docs/examples/basic_json__basic_json.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON array 9 | json j1 = {"one", "two", 3, 4.5, false}; 10 | 11 | // create a copy 12 | json j2(j1); 13 | 14 | // serialize the JSON array 15 | std::cout << j1 << " = " << j2 << '\n'; 16 | std::cout << std::boolalpha << (j1 == j2) << '\n'; 17 | } 18 | -------------------------------------------------------------------------------- /docs/examples/diff.output: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "op": "replace", 4 | "path": "/baz", 5 | "value": "boo" 6 | }, 7 | { 8 | "op": "remove", 9 | "path": "/foo" 10 | }, 11 | { 12 | "op": "add", 13 | "path": "/hello", 14 | "value": [ 15 | "world" 16 | ] 17 | } 18 | ] 19 | 20 | { 21 | "baz": "boo", 22 | "hello": [ 23 | "world" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_json_namespace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // possible use case: use NLOHMANN_JSON_NAMESPACE instead of nlohmann 5 | using json = NLOHMANN_JSON_NAMESPACE::json; 6 | 7 | // macro needed to output the NLOHMANN_JSON_NAMESPACE as string literal 8 | #define Q(x) #x 9 | #define QUOTE(x) Q(x) 10 | 11 | int main() 12 | { 13 | std::cout << QUOTE(NLOHMANN_JSON_NAMESPACE) << std::endl; 14 | } 15 | -------------------------------------------------------------------------------- /docs/examples/object_comparator_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | std::cout << std::boolalpha 9 | << "json::object_comparator_t(\"one\", \"two\") = " << json::object_comparator_t{}("one", "two") << "\n" 10 | << "json::object_comparator_t(\"three\", \"four\") = " << json::object_comparator_t{}("three", "four") << std::endl; 11 | } 12 | -------------------------------------------------------------------------------- /docs/examples/parse__pointers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // a JSON text given as string that is not null-terminated 10 | const char* ptr = "[1,2,3]another value"; 11 | 12 | // parse and serialize JSON 13 | json j_complete = json::parse(ptr, ptr + 7); 14 | std::cout << std::setw(4) << j_complete << "\n\n"; 15 | } 16 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/basic_json/~basic_json.md: -------------------------------------------------------------------------------- 1 | # nlohmann::basic_json::~basic_json 2 | 3 | ```cpp 4 | ~basic_json() noexcept; 5 | ``` 6 | 7 | Destroys the JSON value and frees all allocated memory. 8 | 9 | ## Exception safety 10 | 11 | No-throw guarantee: this member function never throws exceptions. 12 | 13 | ## Complexity 14 | 15 | Linear. 16 | 17 | 18 | 19 | ## Version history 20 | 21 | - Added in version 1.0.0. 22 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Usually, all issues are tracked publicly on [GitHub](https://github.com/nlohmann/json/issues). If you want to make a private report (e.g., for a vulnerability or to attach an example that is not meant to be published), please send an email to . You can use [this key](https://keybase.io/nlohmann/pgp_keys.asc?fingerprint=797167ae41c0a6d9232e48457f3cea63ae251b69) for encryption. 6 | -------------------------------------------------------------------------------- /docs/examples/insert__ilist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON array 9 | json v = {1, 2, 3, 4}; 10 | 11 | // insert range from v2 before the end of array v 12 | auto new_pos = v.insert(v.end(), {7, 8, 9}); 13 | 14 | // output new array and result of insert call 15 | std::cout << *new_pos << '\n'; 16 | std::cout << v << '\n'; 17 | } 18 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator_string_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // different JSON Pointers 9 | json::json_pointer ptr1("/foo/0"); 10 | json::json_pointer ptr2("/a~1b"); 11 | 12 | // implicit conversion to string 13 | std::string s; 14 | s += ptr1; 15 | s += "\n"; 16 | s += ptr2; 17 | 18 | std::cout << s << std::endl; 19 | } 20 | -------------------------------------------------------------------------------- /docs/examples/meta.output: -------------------------------------------------------------------------------- 1 | { 2 | "compiler": { 3 | "c++": "201103", 4 | "family": "gcc", 5 | "version": "12.3.0" 6 | }, 7 | "copyright": "(C) 2013-2022 Niels Lohmann", 8 | "name": "JSON for Modern C++", 9 | "platform": "apple", 10 | "url": "https://github.com/nlohmann/json", 11 | "version": { 12 | "major": 3, 13 | "minor": 11, 14 | "patch": 3, 15 | "string": "3.11.3" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/cmake_target_include_directories/project/Foo.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | #include 11 | 12 | class Foo {}; 13 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | authors: 4 | - family-names: Lohmann 5 | given-names: Niels 6 | orcid: https://orcid.org/0000-0001-9037-795X 7 | email: mail@nlohmann.me 8 | website: https://nlohmann.me 9 | title: "JSON for Modern C++" 10 | version: 3.11.3 11 | date-released: 2023-11-28 12 | license: MIT 13 | repository-code: "https://github.com/nlohmann" 14 | url: https://json.nlohmann.me 15 | -------------------------------------------------------------------------------- /docs/examples/insert__count.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON array 9 | json v = {1, 2, 3, 4}; 10 | 11 | // insert number 7 copies of number 7 before number 3 12 | auto new_pos = v.insert(v.begin() + 2, 7, 7); 13 | 14 | // output new array and result of insert call 15 | std::cout << *new_pos << '\n'; 16 | std::cout << v << '\n'; 17 | } 18 | -------------------------------------------------------------------------------- /.cirrus.yml: -------------------------------------------------------------------------------- 1 | arm_container: 2 | image: gcc:latest 3 | 4 | check_task: 5 | check_script: 6 | - wget https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2.tar.gz 7 | - tar xfz cmake-3.20.2.tar.gz 8 | - cd cmake-3.20.2 9 | - ./configure 10 | - make cmake ctest -j4 11 | - cd .. 12 | - mkdir build 13 | - cd build 14 | - ../cmake-3.20.2/bin/cmake .. -DJSON_FastTests=ON 15 | - make -j4 16 | - cd tests 17 | - ../../cmake-3.20.2/bin/ctest -j4 18 | -------------------------------------------------------------------------------- /docs/examples/diagnostics_standard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | json j; 9 | j["address"]["street"] = "Fake Street"; 10 | j["address"]["housenumber"] = "12"; 11 | 12 | try 13 | { 14 | int housenumber = j["address"]["housenumber"]; 15 | } 16 | catch (const json::exception& e) 17 | { 18 | std::cout << e.what() << '\n'; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/operator_array__keytype_const.c++17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std::string_view_literals; 6 | using json = nlohmann::json; 7 | 8 | int main() 9 | { 10 | // create a JSON object 11 | const json object = 12 | { 13 | {"one", 1}, {"two", 2}, {"three", 2.9} 14 | }; 15 | 16 | // output element with key "two" 17 | std::cout << object["two"sv] << '\n'; 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/swap__reference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create two JSON values 9 | json j1 = {1, 2, 3, 4, 5}; 10 | json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}}; 11 | 12 | // swap the values 13 | j1.swap(j2); 14 | 15 | // output the values 16 | std::cout << "j1 = " << j1 << '\n'; 17 | std::cout << "j2 = " << j2 << '\n'; 18 | } 19 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/home/sponsors.md: -------------------------------------------------------------------------------- 1 | # Sponsors 2 | 3 | You can sponsor this library at [GitHub Sponsors](https://github.com/sponsors/nlohmann). 4 | 5 | ## Named Sponsors 6 | 7 | - [Michael Hartmann](https://github.com/reFX-Mike) 8 | - [Stefan Hagen](https://github.com/sthagen) 9 | - [Steve Sperandeo](https://github.com/homer6) 10 | - [Robert Jefe Lindstädt](https://github.com/eljefedelrodeodeljefe) 11 | - [Steve Wagner](https://github.com/ciroque) 12 | 13 | Thanks everyone! 14 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/LeakTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Test with a leak. 5 | #include 6 | #include 7 | 8 | static volatile void *Sink; 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 11 | if (Size > 0 && *Data == 'H') { 12 | Sink = new int; 13 | Sink = nullptr; 14 | } 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /docs/examples/parse__contiguouscontainer__parser_callback_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // a JSON text given as std::vector 10 | std::vector text = {'[', '1', ',', '2', ',', '3', ']', '\0'}; 11 | 12 | // parse and serialize JSON 13 | json j_complete = json::parse(text); 14 | std::cout << std::setw(4) << j_complete << "\n\n"; 15 | } 16 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/TimeoutEmptyTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer. The fuzzer must find the empty string. 5 | #include 6 | #include 7 | 8 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 9 | static volatile int Zero = 0; 10 | if (!Size) 11 | while(!Zero) 12 | ; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /docs/examples/std_swap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create JSON values 10 | json j1 = {{"one", 1}, {"two", 2}}; 11 | json j2 = {1, 2, 4, 8, 16}; 12 | 13 | std::cout << "j1 = " << j1 << " | j2 = " << j2 << '\n'; 14 | 15 | // swap values 16 | std::swap(j1, j2); 17 | 18 | std::cout << "j1 = " << j1 << " | j2 = " << j2 << std::endl; 19 | } 20 | -------------------------------------------------------------------------------- /tests/cmake_target_include_directories/project/Bar.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | #include "Foo.hpp" 11 | 12 | class Bar : public Foo {}; 13 | -------------------------------------------------------------------------------- /docs/examples/binary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a binary vector 9 | std::vector vec = {0xCA, 0xFE, 0xBA, 0xBE}; 10 | 11 | // create a binary JSON value with subtype 42 12 | json j = json::binary(vec, 42); 13 | 14 | // output type and subtype 15 | std::cout << "type: " << j.type_name() << ", subtype: " << j.get_binary().subtype() << std::endl; 16 | } 17 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/pkg-config.md: -------------------------------------------------------------------------------- 1 | # Pkg-config 2 | 3 | If you are using bare Makefiles, you can use `pkg-config` to generate the include flags that point to where the library is installed: 4 | 5 | ```sh 6 | pkg-config nlohmann_json --cflags 7 | ``` 8 | 9 | Users of the [Meson build system](package_managers.md#meson) will also be able to use a system-wide library, which will be found by `pkg-config`: 10 | 11 | ```meson 12 | json = dependency('nlohmann_json', required: true) 13 | ``` 14 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/afl-driver-stderr.test: -------------------------------------------------------------------------------- 1 | ; Test that not specifying a stderr file isn't broken. 2 | RUN: unset AFL_DRIVER_STDERR_DUPLICATE_FILENAME 3 | RUN: AFLDriverTest 4 | 5 | ; Test that specifying an invalid file causes a crash. 6 | RUN: ASAN_OPTIONS= AFL_DRIVER_STDERR_DUPLICATE_FILENAME="%T" not --crash AFLDriverTest 7 | 8 | ; Test that a file is created when specified as the duplicate stderr. 9 | RUN: AFL_DRIVER_STDERR_DUPLICATE_FILENAME=%t AFLDriverTest 10 | RUN: stat %t 11 | -------------------------------------------------------------------------------- /tools/amalgamate/CHANGES.md: -------------------------------------------------------------------------------- 1 | The following changes have been made to the code with respect to : 2 | 3 | - Resolved inspection results from PyCharm: 4 | - replaced tabs with spaces 5 | - added encoding annotation 6 | - reindented file to remove trailing whitespaces 7 | - unused import `sys` 8 | - membership check 9 | - made function from `_is_within` 10 | - removed unused variable `actual_path` 11 | -------------------------------------------------------------------------------- /docs/examples/get_binary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a binary vector 9 | std::vector vec = {0xCA, 0xFE, 0xBA, 0xBE}; 10 | 11 | // create a binary JSON value with subtype 42 12 | json j = json::binary(vec, 42); 13 | 14 | // output type and subtype 15 | std::cout << "type: " << j.type_name() << ", subtype: " << j.get_binary().subtype() << std::endl; 16 | } 17 | -------------------------------------------------------------------------------- /docs/examples/end.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to one past the last element 12 | json::iterator it = array.end(); 13 | 14 | // decrement the iterator to point to the last element 15 | --it; 16 | 17 | // serialize the element that the iterator points to 18 | std::cout << *it << '\n'; 19 | } 20 | -------------------------------------------------------------------------------- /docs/examples/get_allocator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | auto alloc = json::get_allocator(); 9 | using traits_t = std::allocator_traits; 10 | 11 | json* j = traits_t::allocate(alloc, 1); 12 | traits_t::construct(alloc, j, "Hello, world!"); 13 | 14 | std::cout << *j << std::endl; 15 | 16 | traits_t::destroy(alloc, j); 17 | traits_t::deallocate(alloc, j, 1); 18 | } 19 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/ubsan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # These tests are instrumented with ubsan in non-recovery mode. 2 | 3 | set(CMAKE_CXX_FLAGS 4 | "${LIBFUZZER_FLAGS_BASE} -fsanitize=undefined -fno-sanitize-recover=all") 5 | 6 | set(UbsanTests 7 | SignedIntOverflowTest 8 | ) 9 | 10 | foreach(Test ${UbsanTests}) 11 | add_libfuzzer_test(${Test}-Ubsan SOURCES ../${Test}.cpp) 12 | endforeach() 13 | 14 | # Propagate value into parent directory 15 | set(TestBinaries ${TestBinaries} PARENT_SCOPE) 16 | -------------------------------------------------------------------------------- /docs/examples/rend.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to the reverse-end 12 | json::reverse_iterator it = array.rend(); 13 | 14 | // increment the iterator to point to the first element 15 | --it; 16 | 17 | // serialize the element that the iterator points to 18 | std::cout << *it << '\n'; 19 | } 20 | -------------------------------------------------------------------------------- /tests/abi/inline_ns/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # test linking an old library version without an inline namespace 2 | # with the current library using an inline namespace into the same executable 3 | 4 | # build test executable and add test 5 | add_executable(abi_compat_inline_ns 6 | use_v3_10_5.cpp 7 | use_current.cpp) 8 | target_link_libraries(abi_compat_inline_ns PRIVATE abi_compat_main) 9 | 10 | add_test( 11 | NAME test-abi_compat_inline_ns 12 | COMMAND abi_compat_inline_ns ${DOCTEST_TEST_FILTER}) 13 | -------------------------------------------------------------------------------- /tests/abi/main.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // Copyright (c) 2013-2022 Niels Lohmann . 7 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 8 | // SPDX-License-Identifier: MIT 9 | 10 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 11 | #include "doctest_compatibility.h" 12 | -------------------------------------------------------------------------------- /docs/examples/cend.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to one past the last element 12 | json::const_iterator it = array.cend(); 13 | 14 | // decrement the iterator to point to the last element 15 | --it; 16 | 17 | // serialize the element that the iterator points to 18 | std::cout << *it << '\n'; 19 | } 20 | -------------------------------------------------------------------------------- /docs/examples/crend.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array value 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // get an iterator to the reverse-end 12 | json::const_reverse_iterator it = array.crend(); 13 | 14 | // increment the iterator to point to the first element 15 | --it; 16 | 17 | // serialize the element that the iterator points to 18 | std::cout << *it << '\n'; 19 | } 20 | -------------------------------------------------------------------------------- /docs/examples/diagnostics_extended.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | # define JSON_DIAGNOSTICS 1 4 | #include 5 | 6 | using json = nlohmann::json; 7 | 8 | int main() 9 | { 10 | json j; 11 | j["address"]["street"] = "Fake Street"; 12 | j["address"]["housenumber"] = "12"; 13 | 14 | try 15 | { 16 | int housenumber = j["address"]["housenumber"]; 17 | } 18 | catch (const json::exception& e) 19 | { 20 | std::cout << e.what() << '\n'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/examples/erase__object_t_key_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON object 9 | json j_object = {{"one", 1}, {"two", 2}}; 10 | 11 | // call erase() 12 | auto count_one = j_object.erase("one"); 13 | auto count_three = j_object.erase("three"); 14 | 15 | // print values 16 | std::cout << j_object << '\n'; 17 | std::cout << count_one << " " << count_three << '\n'; 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // different JSON Pointers 9 | json::json_pointer ptr1("/foo"); 10 | json::json_pointer ptr2("/foo/0"); 11 | 12 | // call empty() 13 | std::cout << "last reference token of \"" << ptr1 << "\" is \"" << ptr1.back() << "\"\n" 14 | << "last reference token of \"" << ptr2 << "\" is \"" << ptr2.back() << "\"" << std::endl; 15 | } 16 | -------------------------------------------------------------------------------- /tests/cmake_import/project/main.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | 11 | int main(int argc, char** argv) 12 | { 13 | nlohmann::json j; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/LeakTimeoutTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Test with a leak. 5 | #include 6 | #include 7 | 8 | static volatile int *Sink; 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 11 | if (!Size) return 0; 12 | Sink = new int; 13 | Sink = new int; 14 | while (Sink) *Sink = 0; // Infinite loop. 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /docs/examples/parse__array__parser_callback_t.output: -------------------------------------------------------------------------------- 1 | { 2 | "Image": { 3 | "Animated": false, 4 | "Height": 600, 5 | "IDs": [ 6 | 116, 7 | 943, 8 | 234, 9 | 38793 10 | ], 11 | "Thumbnail": { 12 | "Height": 125, 13 | "Url": "http://www.example.com/image/481989943", 14 | "Width": 100 15 | }, 16 | "Title": "View from 15th Floor", 17 | "Width": 800 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /docs/examples/parse__iterator_pair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // a JSON text given an input with other values 10 | std::vector input = {'[', '1', ',', '2', ',', '3', ']', 'o', 't', 'h', 'e', 'r'}; 11 | 12 | // parse and serialize JSON 13 | json j_complete = json::parse(input.begin(), input.begin() + 7); 14 | std::cout << std::setw(4) << j_complete << "\n\n"; 15 | } 16 | -------------------------------------------------------------------------------- /tests/reports/2016-08-29-fuzz/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
Banner:fuzz
Directory:fuzz-testing/out
Generated on:Mo 29 Aug 2016 22:14:22 CEST
6 |

7 |

8 |

9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/reports/2016-10-02-fuzz/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
Banner:fuzz
Directory:fuzz-testing/out
Generated on:Sun Oct 2 08:51:02 CEST 2016
6 |

7 |

8 |

9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/cmake_add_subdirectory/project/main.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | 11 | int main(int argc, char** argv) 12 | { 13 | nlohmann::json j; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/cmake_fetch_content/project/main.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | 11 | int main(int argc, char** argv) 12 | { 13 | nlohmann::json j; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/cmake_fetch_content2/project/main.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | 11 | int main(int argc, char** argv) 12 | { 13 | nlohmann::json j; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/cmake_import_minver/project/main.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | 11 | int main(int argc, char** argv) 12 | { 13 | nlohmann::json j; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /docs/examples/at__json_pointer.output: -------------------------------------------------------------------------------- 1 | 1 2 | "foo" 3 | [1,2] 4 | 2 5 | "bar" 6 | [1,21] 7 | [json.exception.parse_error.106] parse error: array index '01' must not begin with '0' 8 | [json.exception.parse_error.109] parse error: array index 'one' is not a number 9 | [json.exception.out_of_range.401] array index 4 is out of range 10 | [json.exception.out_of_range.402] array index '-' (2) is out of range 11 | [json.exception.out_of_range.403] key 'foo' not found 12 | [json.exception.out_of_range.404] unresolved reference token 'foo' 13 | -------------------------------------------------------------------------------- /docs/examples/out_of_range.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | try 9 | { 10 | // calling at() for an invalid index 11 | json j = {1, 2, 3, 4}; 12 | j.at(4) = 10; 13 | } 14 | catch (const json::out_of_range& e) 15 | { 16 | // output exception information 17 | std::cout << "message: " << e.what() << '\n' 18 | << "exception id: " << e.id << std::endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/cmake_target_include_directories/project/main.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | 11 | int main(int argc, char** argv) 12 | { 13 | nlohmann::json j; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-customcrossover.test: -------------------------------------------------------------------------------- 1 | RUN: rm -rf %t/CustomCrossover 2 | RUN: mkdir -p %t/CustomCrossover 3 | RUN: echo "0123456789" > %t/CustomCrossover/digits 4 | RUN: echo "abcdefghij" > %t/CustomCrossover/chars 5 | RUN: not LLVMFuzzer-CustomCrossOverTest -seed=1 -use_memcmp=0 -runs=100000 %t/CustomCrossover 2>&1 | FileCheck %s --check-prefix=LLVMFuzzerCustomCrossover 6 | RUN: rm -rf %t/CustomCrossover 7 | 8 | LLVMFuzzerCustomCrossover: In LLVMFuzzerCustomCrossover 9 | LLVMFuzzerCustomCrossover: BINGO 10 | 11 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/NthRunCrashTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Crash on the N-th execution. 5 | #include 6 | #include 7 | #include 8 | 9 | static int Counter; 10 | 11 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 12 | if (Counter++ == 1000) { 13 | std::cout << "BINGO; Found the target, exiting\n"; 14 | exit(1); 15 | } 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /docs/examples/basic_json__size_type_basic_json.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create an array by creating copies of a JSON value 9 | json value = "Hello"; 10 | json array_0 = json(0, value); 11 | json array_1 = json(1, value); 12 | json array_5 = json(5, value); 13 | 14 | // serialize the JSON arrays 15 | std::cout << array_0 << '\n'; 16 | std::cout << array_1 << '\n'; 17 | std::cout << array_5 << '\n'; 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/type_error.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | try 9 | { 10 | // calling push_back() on a string value 11 | json j = "string"; 12 | j.push_back("another string"); 13 | } 14 | catch (const json::type_error& e) 15 | { 16 | // output exception information 17 | std::cout << "message: " << e.what() << '\n' 18 | << "exception id: " << e.id << std::endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/README.output: -------------------------------------------------------------------------------- 1 | { 2 | "answer": { 3 | "everything": 42 4 | }, 5 | "happy": true, 6 | "list": [ 7 | 1, 8 | 0, 9 | 2 10 | ], 11 | "name": "Niels", 12 | "new": { 13 | "key": { 14 | "value": [ 15 | "another", 16 | "list" 17 | ] 18 | } 19 | }, 20 | "nothing": null, 21 | "object": { 22 | "currency": "USD", 23 | "value": 42.99 24 | }, 25 | "pi": 3.141, 26 | "size": 8 27 | } 28 | -------------------------------------------------------------------------------- /docs/examples/exception.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | try 9 | { 10 | // calling at() for a non-existing key 11 | json j = {{"foo", "bar"}}; 12 | json k = j.at("non-existing"); 13 | } 14 | catch (const json::exception& e) 15 | { 16 | // output exception information 17 | std::cout << "message: " << e.what() << '\n' 18 | << "exception id: " << e.id << std::endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator_add_binary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON pointer 9 | json::json_pointer ptr("/foo"); 10 | 11 | // append a JSON Pointer 12 | std::cout << "\"" << ptr / json::json_pointer("/bar/baz") << "\"\n"; 13 | 14 | // append a string 15 | std::cout << "\"" << ptr / "fob" << "\"\n"; 16 | 17 | // append an array index 18 | std::cout << "\"" << ptr / 42 << "\"" << std::endl; 19 | } 20 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__pop_back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create empty JSON Pointer 9 | json::json_pointer ptr("/foo/bar/baz"); 10 | std::cout << "\"" << ptr << "\"\n"; 11 | 12 | // call pop_back() 13 | ptr.pop_back(); 14 | std::cout << "\"" << ptr << "\"\n"; 15 | 16 | ptr.pop_back(); 17 | std::cout << "\"" << ptr << "\"\n"; 18 | 19 | ptr.pop_back(); 20 | std::cout << "\"" << ptr << "\"\n"; 21 | } 22 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__push_back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create empty JSON Pointer 9 | json::json_pointer ptr; 10 | std::cout << "\"" << ptr << "\"\n"; 11 | 12 | // call push_back() 13 | ptr.push_back("foo"); 14 | std::cout << "\"" << ptr << "\"\n"; 15 | 16 | ptr.push_back("0"); 17 | std::cout << "\"" << ptr << "\"\n"; 18 | 19 | ptr.push_back("bar"); 20 | std::cout << "\"" << ptr << "\"\n"; 21 | } 22 | -------------------------------------------------------------------------------- /docs/examples/swap__binary_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a binary value 9 | json value = json::binary({1, 2, 3}); 10 | 11 | // create a binary_t 12 | json::binary_t binary = {{4, 5, 6}}; 13 | 14 | // swap the object stored in the JSON value 15 | value.swap(binary); 16 | 17 | // output the values 18 | std::cout << "value = " << value << '\n'; 19 | std::cout << "binary = " << json(binary) << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/trace-malloc.test: -------------------------------------------------------------------------------- 1 | RUN: LLVMFuzzer-TraceMallocTest -seed=1 -trace_malloc=1 -runs=10000 2>&1 | FileCheck %s 2 | CHECK-DAG: MallocFreeTracer: STOP 0 0 (same) 3 | CHECK-DAG: MallocFreeTracer: STOP 0 1 (DIFFERENT) 4 | CHECK-DAG: MallocFreeTracer: STOP 1 0 (DIFFERENT) 5 | CHECK-DAG: MallocFreeTracer: STOP 1 1 (same) 6 | 7 | RUN: LLVMFuzzer-TraceMallocTest -seed=1 -trace_malloc=2 -runs=1000 2>&1 | FileCheck %s --check-prefix=TRACE2 8 | TRACE2-DAG: FREE[0] 9 | TRACE2-DAG: MALLOC[0] 10 | TRACE2-DAG: in LLVMFuzzerTestOneInput 11 | -------------------------------------------------------------------------------- /docs/examples/swap__string_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON value 9 | json value = { "the good", "the bad", "the ugly" }; 10 | 11 | // create string_t 12 | json::string_t string = "the fast"; 13 | 14 | // swap the object stored in the JSON value 15 | value[1].swap(string); 16 | 17 | // output the values 18 | std::cout << "value = " << value << '\n'; 19 | std::cout << "string = " << string << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/swap__array_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON value 9 | json value = {{"array", {1, 2, 3, 4}}}; 10 | 11 | // create an array_t 12 | json::array_t array = {"Snap", "Crackle", "Pop"}; 13 | 14 | // swap the array stored in the JSON value 15 | value["array"].swap(array); 16 | 17 | // output the values 18 | std::cout << "value = " << value << '\n'; 19 | std::cout << "array = " << array << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /include/nlohmann/detail/meta/call_std/end.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | 15 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); 16 | 17 | NLOHMANN_JSON_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /include/nlohmann/detail/meta/call_std/begin.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | 15 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); 16 | 17 | NLOHMANN_JSON_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /docs/examples/parse_error.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | try 9 | { 10 | // parsing input with a syntax error 11 | json::parse("[1,2,3,]"); 12 | } 13 | catch (const json::parse_error& e) 14 | { 15 | // output exception information 16 | std::cout << "message: " << e.what() << '\n' 17 | << "exception id: " << e.id << '\n' 18 | << "byte position of error: " << e.byte << std::endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/push_back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON values 9 | json array = {1, 2, 3, 4, 5}; 10 | json null; 11 | 12 | // print values 13 | std::cout << array << '\n'; 14 | std::cout << null << '\n'; 15 | 16 | // add values 17 | array.push_back(6); 18 | array += 7; 19 | null += "first"; 20 | null += "second"; 21 | 22 | // print values 23 | std::cout << array << '\n'; 24 | std::cout << null << '\n'; 25 | } 26 | -------------------------------------------------------------------------------- /docs/examples/count__object_t_key_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON object 9 | json j_object = {{"one", 1}, {"two", 2}}; 10 | 11 | // call count() 12 | auto count_two = j_object.count("two"); 13 | auto count_three = j_object.count("three"); 14 | 15 | // print values 16 | std::cout << "number of elements with key \"two\": " << count_two << '\n'; 17 | std::cout << "number of elements with key \"three\": " << count_three << '\n'; 18 | } 19 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/ThreadedLeakTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // The fuzzer should find a leak in a non-main thread. 5 | #include 6 | #include 7 | #include 8 | 9 | static volatile int *Sink; 10 | 11 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 12 | if (Size == 0) return 0; 13 | if (Data[0] != 'F') return 0; 14 | std::thread T([&] { Sink = new int; }); 15 | T.join(); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /docs/examples/emplace_back.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON values 9 | json array = {1, 2, 3, 4, 5}; 10 | json null; 11 | 12 | // print values 13 | std::cout << array << '\n'; 14 | std::cout << null << '\n'; 15 | 16 | // add values 17 | array.emplace_back(6); 18 | null.emplace_back("first"); 19 | null.emplace_back(3, "second"); 20 | 21 | // print values 22 | std::cout << array << '\n'; 23 | std::cout << null << '\n'; 24 | } 25 | -------------------------------------------------------------------------------- /docs/examples/insert__range_object.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create two JSON objects 9 | json j1 = {{"one", "eins"}, {"two", "zwei"}}; 10 | json j2 = {{"eleven", "elf"}, {"seventeen", "siebzehn"}}; 11 | 12 | // output objects 13 | std::cout << j1 << '\n'; 14 | std::cout << j2 << '\n'; 15 | 16 | // insert range from j2 to j1 17 | j1.insert(j2.begin(), j2.end()); 18 | 19 | // output result of insert call 20 | std::cout << j1 << '\n'; 21 | } 22 | -------------------------------------------------------------------------------- /docs/examples/to_string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | using std::to_string; 6 | 7 | int main() 8 | { 9 | // create values 10 | json j = {{"one", 1}, {"two", 2}}; 11 | int i = 42; 12 | 13 | // use ADL to select best to_string function 14 | auto j_str = to_string(j); // calling nlohmann::to_string 15 | auto i_str = to_string(i); // calling std::to_string 16 | 17 | // serialize without indentation 18 | std::cout << j_str << "\n\n" 19 | << i_str << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/SingleStrcmpTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer. The fuzzer must find a particular string. 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 11 | char *S = (char*)Data; 12 | if (Size >= 7 && !strcmp(S, "qwerty")) { 13 | fprintf(stderr, "BINGO\n"); 14 | exit(1); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /docs/examples/erase__keytype.c++17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std::string_view_literals; 6 | using json = nlohmann::json; 7 | 8 | int main() 9 | { 10 | // create a JSON object 11 | json j_object = {{"one", 1}, {"two", 2}}; 12 | 13 | // call erase() 14 | auto count_one = j_object.erase("one"sv); 15 | auto count_three = j_object.erase("three"sv); 16 | 17 | // print values 18 | std::cout << j_object << '\n'; 19 | std::cout << count_one << " " << count_three << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/insert__range.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON array 9 | json v = {1, 2, 3, 4}; 10 | 11 | // create a JSON array to copy values from 12 | json v2 = {"one", "two", "three", "four"}; 13 | 14 | // insert range from v2 before the end of array v 15 | auto new_pos = v.insert(v.end(), v2.begin(), v2.end()); 16 | 17 | // output new array and result of insert call 18 | std::cout << *new_pos << '\n'; 19 | std::cout << v << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/operator__equal__specializations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | nlohmann::json uj1 = {{"version", 1}, {"type", "integer"}}; 10 | nlohmann::json uj2 = {{"type", "integer"}, {"version", 1}}; 11 | 12 | nlohmann::ordered_json oj1 = {{"version", 1}, {"type", "integer"}}; 13 | nlohmann::ordered_json oj2 = {{"type", "integer"}, {"version", 1}}; 14 | 15 | std::cout << std::boolalpha << (uj1 == uj2) << '\n' << (oj1 == oj2) << std::endl; 16 | } 17 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/SingleMemcmpTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer. The fuzzer must find a particular string. 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 11 | char *S = (char*)Data; 12 | if (Size >= 6 && !memcmp(S, "qwerty", 6)) { 13 | fprintf(stderr, "BINGO\n"); 14 | exit(1); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/SingleStrncmpTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer. The fuzzer must find a particular string. 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 11 | char *S = (char*)Data; 12 | if (Size >= 6 && !strncmp(S, "qwerty", 6)) { 13 | fprintf(stderr, "BINGO\n"); 14 | exit(1); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /docs/examples/invalid_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | try 9 | { 10 | // calling iterator::key() on non-object iterator 11 | json j = "string"; 12 | json::iterator it = j.begin(); 13 | auto k = it.key(); 14 | } 15 | catch (const json::invalid_iterator& e) 16 | { 17 | // output exception information 18 | std::cout << "message: " << e.what() << '\n' 19 | << "exception id: " << e.id << std::endl; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/null.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::null 2 | 3 | ```cpp 4 | virtual bool null() = 0; 5 | ``` 6 | 7 | A null value was read. 8 | 9 | ## Return value 10 | 11 | Whether parsing should proceed. 12 | 13 | ## Examples 14 | 15 | ??? example 16 | 17 | The example below shows how the SAX interface is used. 18 | 19 | ```cpp 20 | --8<-- "examples/sax_parse.cpp" 21 | ``` 22 | 23 | Output: 24 | 25 | ```json 26 | --8<-- "examples/sax_parse.output" 27 | ``` 28 | 29 | ## Version history 30 | 31 | - Added in version 3.2.0. 32 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/CounterTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Test for a fuzzer: must find the case where a particular basic block is 5 | // executed many times. 6 | #include 7 | 8 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 9 | int Num = 0; 10 | for (size_t i = 0; i < Size; i++) 11 | if (Data[i] == 'A' + i) 12 | Num++; 13 | if (Num >= 4) { 14 | std::cerr << "BINGO!\n"; 15 | exit(1); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-flags.test: -------------------------------------------------------------------------------- 1 | RUN: LLVMFuzzer-SimpleTest -foo_bar=1 2>&1 | FileCheck %s --check-prefix=FOO_BAR 2 | FOO_BAR: WARNING: unrecognized flag '-foo_bar=1'; use -help=1 to list all flags 3 | FOO_BAR: BINGO 4 | 5 | RUN: LLVMFuzzer-SimpleTest -runs=10 --max_len=100 2>&1 | FileCheck %s --check-prefix=DASH_DASH 6 | DASH_DASH: WARNING: did you mean '-max_len=100' (single dash)? 7 | DASH_DASH: INFO: A corpus is not provided, starting from an empty corpus 8 | 9 | RUN: LLVMFuzzer-SimpleTest -help=1 2>&1 | FileCheck %s --check-prefix=NO_INTERNAL 10 | NO_INTERNAL-NOT: internal flag 11 | -------------------------------------------------------------------------------- /docs/examples/swap__object_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON value 9 | json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} }; 10 | 11 | // create an object_t 12 | json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}}; 13 | 14 | // swap the object stored in the JSON value 15 | value["translation"].swap(object); 16 | 17 | // output the values 18 | std::cout << "value = " << value << '\n'; 19 | std::cout << "object = " << object << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/NullDerefOnEmptyTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer. The fuzzer must find the empty string. 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static volatile int *Null = 0; 11 | 12 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 13 | if (Size == 0) { 14 | std::cout << "Found the target, dereferencing NULL\n"; 15 | *Null = 1; 16 | } 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /docs/examples/accept__string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // a valid JSON text 10 | auto valid_text = R"( 11 | { 12 | "numbers": [1, 2, 3] 13 | } 14 | )"; 15 | 16 | // an invalid JSON text 17 | auto invalid_text = R"( 18 | { 19 | "strings": ["extra", "comma", ] 20 | } 21 | )"; 22 | 23 | std::cout << std::boolalpha 24 | << json::accept(valid_text) << ' ' 25 | << json::accept(invalid_text) << '\n'; 26 | } 27 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/DivTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer: find the interesting argument for div. 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static volatile int Sink; 12 | 13 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 14 | if (Size < 4) return 0; 15 | int a; 16 | memcpy(&a, Data, 4); 17 | Sink = 12345678 / (987654 - a); 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-finalstats.test: -------------------------------------------------------------------------------- 1 | RUN: LLVMFuzzer-SimpleTest -seed=1 -runs=77 -print_final_stats=1 2>&1 | FileCheck %s --check-prefix=FINAL_STATS 2 | FINAL_STATS: stat::number_of_executed_units: 77 3 | FINAL_STATS: stat::average_exec_per_sec: 0 4 | FINAL_STATS: stat::new_units_added: 5 | FINAL_STATS: stat::slowest_unit_time_sec: 0 6 | FINAL_STATS: stat::peak_rss_mb: 7 | 8 | RUN: LLVMFuzzer-SimpleTest %S/dict1.txt -runs=33 -print_final_stats=1 2>&1 | FileCheck %s --check-prefix=FINAL_STATS1 9 | FINAL_STATS1: stat::number_of_executed_units: 33 10 | FINAL_STATS1: stat::peak_rss_mb: 11 | 12 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/end_array.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::end_array 2 | 3 | ```cpp 4 | virtual bool end_array() = 0; 5 | ``` 6 | 7 | The end of an array was read. 8 | 9 | ## Return value 10 | 11 | Whether parsing should proceed. 12 | 13 | ## Examples 14 | 15 | ??? example 16 | 17 | The example below shows how the SAX interface is used. 18 | 19 | ```cpp 20 | --8<-- "examples/sax_parse.cpp" 21 | ``` 22 | 23 | Output: 24 | 25 | ```json 26 | --8<-- "examples/sax_parse.output" 27 | ``` 28 | 29 | ## Version history 30 | 31 | - Added in version 3.2.0. 32 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/minimize_crash.test: -------------------------------------------------------------------------------- 1 | RUN: echo 'Hi!rv349f34t3gg' > not_minimal_crash 2 | RUN: LLVMFuzzer-NullDerefTest -minimize_crash=1 not_minimal_crash -max_total_time=2 2>&1 | FileCheck %s 3 | CHECK: CRASH_MIN: failed to minimize beyond minimized-from-{{.*}} (3 bytes), exiting 4 | RUN: LLVMFuzzer-NullDerefTest -minimize_crash=1 not_minimal_crash -max_total_time=2 -exact_artifact_path=exact_minimized_path 2>&1 | FileCheck %s --check-prefix=CHECK_EXACT 5 | CHECK_EXACT: CRASH_MIN: failed to minimize beyond exact_minimized_path (3 bytes), exiting 6 | RUN: rm not_minimal_crash minimized-from-* exact_minimized_path 7 | -------------------------------------------------------------------------------- /docs/examples/to_bson.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | using namespace nlohmann::literals; 7 | 8 | int main() 9 | { 10 | // create a JSON value 11 | json j = R"({"compact": true, "schema": 0})"_json; 12 | 13 | // serialize it to BSON 14 | std::vector v = json::to_bson(j); 15 | 16 | // print the vector content 17 | for (auto& byte : v) 18 | { 19 | std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " "; 20 | } 21 | std::cout << std::endl; 22 | } 23 | -------------------------------------------------------------------------------- /docs/examples/to_cbor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | using namespace nlohmann::literals; 7 | 8 | int main() 9 | { 10 | // create a JSON value 11 | json j = R"({"compact": true, "schema": 0})"_json; 12 | 13 | // serialize it to CBOR 14 | std::vector v = json::to_cbor(j); 15 | 16 | // print the vector content 17 | for (auto& byte : v) 18 | { 19 | std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " "; 20 | } 21 | std::cout << std::endl; 22 | } 23 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json 2 | 3 | ```cpp 4 | using json = basic_json<>; 5 | ``` 6 | 7 | This type is the default specialization of the [basic_json](basic_json/index.md) class which uses the standard template 8 | types. 9 | 10 | ## Examples 11 | 12 | ??? example 13 | 14 | The example below demonstrates how to use the type `nlohmann::json`. 15 | 16 | ```cpp 17 | --8<-- "examples/README.cpp" 18 | ``` 19 | 20 | Output: 21 | 22 | ```json 23 | --8<-- "examples/README.output" 24 | ``` 25 | 26 | ## Version history 27 | 28 | Since version 1.0.0. 29 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/end_object.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::end_object 2 | 3 | ```cpp 4 | virtual bool end_object() = 0; 5 | ``` 6 | 7 | The end of an object was read. 8 | 9 | ## Return value 10 | 11 | Whether parsing should proceed. 12 | 13 | ## Examples 14 | 15 | ??? example 16 | 17 | The example below shows how the SAX interface is used. 18 | 19 | ```cpp 20 | --8<-- "examples/sax_parse.cpp" 21 | ``` 22 | 23 | Output: 24 | 25 | ```json 26 | --8<-- "examples/sax_parse.output" 27 | ``` 28 | 29 | ## Version history 30 | 31 | - Added in version 3.2.0. 32 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/uninstrumented/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # These tests are not instrumented with coverage and don't 2 | # have coverage rt in the binary. 3 | 4 | set(CMAKE_CXX_FLAGS 5 | "${LIBFUZZER_FLAGS_BASE} -fno-sanitize=all -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters,trace-pc-guard") 6 | 7 | set(UninstrumentedTests 8 | UninstrumentedTest 9 | ) 10 | 11 | foreach(Test ${UninstrumentedTests}) 12 | add_libfuzzer_test(${Test}-Uninstrumented SOURCES ../${Test}.cpp) 13 | endforeach() 14 | 15 | # Propagate value into parent directory 16 | set(TestBinaries ${TestBinaries} PARENT_SCOPE) 17 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/fuzzer-oom.test: -------------------------------------------------------------------------------- 1 | RUN: not LLVMFuzzer-OutOfMemoryTest -rss_limit_mb=300 2>&1 | FileCheck %s 2 | CHECK: ERROR: libFuzzer: out-of-memory (used: {{.*}}; limit: 300Mb) 3 | CHECK: Test unit written to ./oom- 4 | SUMMARY: libFuzzer: out-of-memory 5 | 6 | RUN: not LLVMFuzzer-OutOfMemorySingleLargeMallocTest 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC 7 | SINGLE_LARGE_MALLOC: libFuzzer: out-of-memory (malloc(42{{.*}})) 8 | SINGLE_LARGE_MALLOC: in LLVMFuzzerTestOneInput 9 | 10 | # Check that -rss_limit_mb=0 means no limit. 11 | RUN: LLVMFuzzer-AccumulateAllocationsTest -runs=1000 -rss_limit_mb=0 12 | -------------------------------------------------------------------------------- /docs/examples/items.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON values 9 | json j_object = {{"one", 1}, {"two", 2}}; 10 | json j_array = {1, 2, 4, 8, 16}; 11 | 12 | // example for an object 13 | for (auto& x : j_object.items()) 14 | { 15 | std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; 16 | } 17 | 18 | // example for an array 19 | for (auto& x : j_array.items()) 20 | { 21 | std::cout << "key: " << x.key() << ", value: " << x.value() << '\n'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator_add.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON pointer 9 | json::json_pointer ptr("/foo"); 10 | std::cout << "\"" << ptr << "\"\n"; 11 | 12 | // append a JSON Pointer 13 | ptr /= json::json_pointer("/bar/baz"); 14 | std::cout << "\"" << ptr << "\"\n"; 15 | 16 | // append a string 17 | ptr /= "fob"; 18 | std::cout << "\"" << ptr << "\"\n"; 19 | 20 | // append an array index 21 | ptr /= 42; 22 | std::cout << "\"" << ptr << "\"" << std::endl; 23 | } 24 | -------------------------------------------------------------------------------- /docs/examples/operator_array__size_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON array 9 | json array = {1, 2, 3, 4, 5}; 10 | 11 | // output element at index 3 (fourth element) 12 | std::cout << array[3] << '\n'; 13 | 14 | // change last element to 6 15 | array[array.size() - 1] = 6; 16 | 17 | // output changed array 18 | std::cout << array << '\n'; 19 | 20 | // write beyond array limit 21 | array[10] = 11; 22 | 23 | // output changed array 24 | std::cout << array << '\n'; 25 | } 26 | -------------------------------------------------------------------------------- /docs/examples/to_msgpack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | using namespace nlohmann::literals; 7 | 8 | int main() 9 | { 10 | // create a JSON value 11 | json j = R"({"compact": true, "schema": 0})"_json; 12 | 13 | // serialize it to MessagePack 14 | std::vector v = json::to_msgpack(j); 15 | 16 | // print the vector content 17 | for (auto& byte : v) 18 | { 19 | std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " "; 20 | } 21 | std::cout << std::endl; 22 | } 23 | -------------------------------------------------------------------------------- /tests/cmake_fetch_content2/project/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(DummyImport CXX) 4 | 5 | include(FetchContent) 6 | 7 | get_filename_component(GIT_REPOSITORY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ABSOLUTE) 8 | FetchContent_Declare(json GIT_REPOSITORY ${GIT_REPOSITORY_DIRECTORY} GIT_TAG HEAD) 9 | FetchContent_MakeAvailable(json) 10 | 11 | add_executable(with_namespace_target main.cpp) 12 | target_link_libraries(with_namespace_target nlohmann_json::nlohmann_json) 13 | 14 | add_executable(without_namespace_target main.cpp) 15 | target_link_libraries(without_namespace_target nlohmann_json) 16 | -------------------------------------------------------------------------------- /docs/examples/array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON arrays 9 | json j_no_init_list = json::array(); 10 | json j_empty_init_list = json::array({}); 11 | json j_nonempty_init_list = json::array({1, 2, 3, 4}); 12 | json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} }); 13 | 14 | // serialize the JSON arrays 15 | std::cout << j_no_init_list << '\n'; 16 | std::cout << j_empty_init_list << '\n'; 17 | std::cout << j_nonempty_init_list << '\n'; 18 | std::cout << j_list_of_pairs << '\n'; 19 | } 20 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/AccumulateAllocationsTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Test with a more mallocs than frees, but no leak. 5 | #include 6 | #include 7 | 8 | const int kAllocatedPointersSize = 10000; 9 | int NumAllocatedPointers = 0; 10 | int *AllocatedPointers[kAllocatedPointersSize]; 11 | 12 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 13 | if (NumAllocatedPointers < kAllocatedPointersSize) 14 | AllocatedPointers[NumAllocatedPointers++] = new int; 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.9 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "nlohmann-json", 8 | platforms: [ 9 | .iOS(.v12), .macOS(.v10_13), .tvOS(.v12), .watchOS(.v4) 10 | ], 11 | products: [ 12 | .library(name: "json", targets: ["json"]) 13 | ], 14 | targets: [ 15 | .target( 16 | name: "json", 17 | path: "single_include/nlohmann", 18 | publicHeadersPath: "." 19 | ) 20 | ], 21 | cxxLanguageStandard: .cxx11 22 | ) 23 | -------------------------------------------------------------------------------- /docs/examples/count__keytype.c++17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std::string_view_literals; 6 | using json = nlohmann::json; 7 | 8 | int main() 9 | { 10 | // create a JSON object 11 | json j_object = {{"one", 1}, {"two", 2}}; 12 | 13 | // call count() 14 | auto count_two = j_object.count("two"sv); 15 | auto count_three = j_object.count("three"sv); 16 | 17 | // print values 18 | std::cout << "number of elements with key \"two\": " << count_two << '\n'; 19 | std::cout << "number of elements with key \"three\": " << count_three << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/from_cbor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create byte vector 10 | std::vector v = {0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 11 | 0x74, 0xf5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6d, 12 | 0x61, 0x00 13 | }; 14 | 15 | // deserialize it with CBOR 16 | json j = json::from_cbor(v); 17 | 18 | // print the deserialized JSON value 19 | std::cout << std::setw(2) << j << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /include/nlohmann/detail/meta/identity_tag.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | namespace detail 15 | { 16 | 17 | // dispatching helper struct 18 | template struct identity_tag {}; 19 | 20 | } // namespace detail 21 | NLOHMANN_JSON_NAMESPACE_END 22 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/RepeatedMemcmp.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 11 | int Matches = 0; 12 | for (size_t i = 0; i + 2 < Size; i += 3) { 13 | const char *Pat = i % 2 ? "foo" : "bar"; 14 | if (!memcmp(Data + i, Pat, 3)) 15 | Matches++; 16 | } 17 | if (Matches > 20) { 18 | fprintf(stderr, "BINGO!\n"); 19 | exit(1); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/SpamyTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // The test spams to stderr and stdout. 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 12 | assert(Data); 13 | printf("PRINTF_STDOUT\n"); 14 | fflush(stdout); 15 | fprintf(stderr, "PRINTF_STDERR\n"); 16 | std::cout << "STREAM_COUT\n"; 17 | std::cout.flush(); 18 | std::cerr << "STREAM_CERR\n"; 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/abi/diag/diag.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | std::size_t json_sizeof_diag_on(); 14 | std::size_t json_sizeof_diag_on_explicit(); 15 | 16 | std::size_t json_sizeof_diag_off(); 17 | std::size_t json_sizeof_diag_off_explicit(); 18 | 19 | void json_at_diag_on(); 20 | void json_at_diag_off(); 21 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | version: 1 2 | 3 | labels: 4 | - label: "documentation" 5 | files: 6 | - "README.md" 7 | 8 | - label: "documentation" 9 | files: 10 | - "docs/.*" 11 | 12 | - label: "tests" 13 | files: 14 | - "tests/.*" 15 | 16 | - label: "CMake" 17 | files: 18 | - ".*CMakeLists.txt" 19 | 20 | - label: "CMake" 21 | files: 22 | - "cmake/.*" 23 | 24 | - label: "CI" 25 | files: 26 | - "github/workflows/.*" 27 | 28 | - label: "CI" 29 | files: 30 | - "github/external_ci/.*" 31 | 32 | - label: "S" 33 | size-below: 10 34 | - label: "M" 35 | size-above: 9 36 | size-below: 100 37 | - label: "L" 38 | size-above: 100 39 | -------------------------------------------------------------------------------- /docs/examples/from_msgpack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create byte vector 10 | std::vector v = {0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 11 | 0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 12 | 0x61, 0x00 13 | }; 14 | 15 | // deserialize it with MessagePack 16 | json j = json::from_msgpack(v); 17 | 18 | // print the deserialized JSON value 19 | std::cout << std::setw(2) << j << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /tests/cuda_example/json_cuda.cu: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include 10 | 11 | int main() 12 | { 13 | nlohmann::ordered_json json = {"Test"}; 14 | json.dump(); 15 | 16 | // regression for #3013 (ordered_json::reset() compile error with nvcc) 17 | nlohmann::ordered_json metadata; 18 | metadata.erase("key"); 19 | } 20 | -------------------------------------------------------------------------------- /tests/src/unit-windows_h.cpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ (supporting code) 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #include "doctest_compatibility.h" 10 | #undef WIN32_LEAN_AND_MEAN 11 | #undef NOMINMAX 12 | 13 | #ifdef _WIN32 14 | #include 15 | #endif 16 | 17 | #include 18 | using nlohmann::json; 19 | 20 | TEST_CASE("include windows.h") 21 | { 22 | CHECK(true); 23 | } 24 | -------------------------------------------------------------------------------- /docs/examples/find__object_t_key_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON object 9 | json j_object = {{"one", 1}, {"two", 2}}; 10 | 11 | // call find 12 | auto it_two = j_object.find("two"); 13 | auto it_three = j_object.find("three"); 14 | 15 | // print values 16 | std::cout << std::boolalpha; 17 | std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n'; 18 | std::cout << "value at key \"two\": " << *it_two << '\n'; 19 | std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/operator_deserialize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using json = nlohmann::json; 7 | 8 | int main() 9 | { 10 | // create stream with serialized JSON 11 | std::stringstream ss; 12 | ss << R"({ 13 | "number": 23, 14 | "string": "Hello, world!", 15 | "array": [1, 2, 3, 4, 5], 16 | "boolean": false, 17 | "null": null 18 | })"; 19 | 20 | // create JSON value and read the serialization from the stream 21 | json j; 22 | ss >> j; 23 | 24 | // serialize JSON 25 | std::cout << std::setw(2) << j << '\n'; 26 | } 27 | -------------------------------------------------------------------------------- /tests/cmake_import/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_test(NAME cmake_import_configure 2 | COMMAND ${CMAKE_COMMAND} 3 | -G "${CMAKE_GENERATOR}" 4 | -A "${CMAKE_GENERATOR_PLATFORM}" 5 | -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} 6 | -Dnlohmann_json_DIR=${PROJECT_BINARY_DIR} 7 | ${CMAKE_CURRENT_SOURCE_DIR}/project 8 | ) 9 | add_test(NAME cmake_import_build 10 | COMMAND ${CMAKE_COMMAND} --build . 11 | ) 12 | set_tests_properties(cmake_import_configure PROPERTIES 13 | FIXTURES_SETUP cmake_import 14 | LABELS not_reproducible 15 | ) 16 | set_tests_properties(cmake_import_build PROPERTIES 17 | FIXTURES_REQUIRED cmake_import 18 | LABELS not_reproducible 19 | ) 20 | -------------------------------------------------------------------------------- /docs/examples/json_lines.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // JSON Lines (see https://jsonlines.org) 10 | std::stringstream input; 11 | input << R"({"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]} 12 | {"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]} 13 | {"name": "May", "wins": []} 14 | {"name": "Deloise", "wins": [["three of a kind", "5♣"]]} 15 | )"; 16 | 17 | std::string line; 18 | while (std::getline(input, line)) 19 | { 20 | std::cout << json::parse(line) << std::endl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/examples/operator_ltlt__basic_json.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create JSON values 10 | json j_object = {{"one", 1}, {"two", 2}}; 11 | json j_array = {1, 2, 4, 8, 16}; 12 | 13 | // serialize without indentation 14 | std::cout << j_object << "\n\n"; 15 | std::cout << j_array << "\n\n"; 16 | 17 | // serialize with indentation 18 | std::cout << std::setw(4) << j_object << "\n\n"; 19 | std::cout << std::setw(2) << j_array << "\n\n"; 20 | std::cout << std::setw(1) << std::setfill('\t') << j_object << "\n\n"; 21 | } 22 | -------------------------------------------------------------------------------- /docs/examples/contains__object_t_key_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | using namespace nlohmann::literals; 6 | 7 | int main() 8 | { 9 | // create some JSON values 10 | json j_object = R"( {"key": "value"} )"_json; 11 | json j_array = R"( [1, 2, 3] )"_json; 12 | 13 | // call contains 14 | std::cout << std::boolalpha << 15 | "j_object contains 'key': " << j_object.contains("key") << '\n' << 16 | "j_object contains 'another': " << j_object.contains("another") << '\n' << 17 | "j_array contains 'key': " << j_array.contains("key") << std::endl; 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/nlohmann_define_type_non_intrusive_only_serialize_macro.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | using namespace nlohmann::literals; 6 | 7 | namespace ns 8 | { 9 | struct person 10 | { 11 | std::string name; 12 | std::string address; 13 | int age; 14 | }; 15 | 16 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(person, name, address, age) 17 | } // namespace ns 18 | 19 | int main() 20 | { 21 | ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; 22 | 23 | // serialization: person -> json 24 | json j = p; 25 | std::cout << "serialization: " << j << std::endl; 26 | } 27 | -------------------------------------------------------------------------------- /docs/examples/to_json.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | namespace ns 7 | { 8 | // a simple struct to model a person 9 | struct person 10 | { 11 | std::string name; 12 | std::string address; 13 | int age; 14 | }; 15 | } // namespace ns 16 | 17 | namespace ns 18 | { 19 | void to_json(json& j, const person& p) 20 | { 21 | j = json{ {"name", p.name}, {"address", p.address}, {"age", p.age} }; 22 | } 23 | } // namespace ns 24 | 25 | int main() 26 | { 27 | ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; 28 | 29 | json j = p; 30 | 31 | std::cout << j << std::endl; 32 | } 33 | -------------------------------------------------------------------------------- /cmake/scripts/gen_bazel_build_file.cmake: -------------------------------------------------------------------------------- 1 | # generate Bazel BUILD file 2 | 3 | set(PROJECT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../..") 4 | set(BUILD_FILE "${PROJECT_ROOT}/BUILD.bazel") 5 | 6 | file(GLOB_RECURSE HEADERS LIST_DIRECTORIES false RELATIVE "${PROJECT_ROOT}" "include/*.hpp") 7 | 8 | file(WRITE "${BUILD_FILE}" [=[ 9 | cc_library( 10 | name = "json", 11 | hdrs = [ 12 | ]=]) 13 | 14 | foreach(header ${HEADERS}) 15 | file(APPEND "${BUILD_FILE}" " \"${header}\",\n") 16 | endforeach() 17 | 18 | file(APPEND "${BUILD_FILE}" [=[ 19 | ], 20 | includes = ["include"], 21 | visibility = ["//visibility:public"], 22 | alwayslink = True, 23 | ) 24 | ]=]) 25 | -------------------------------------------------------------------------------- /docs/examples/from_bjdata.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create byte vector 10 | std::vector v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61, 11 | 0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68, 12 | 0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D 13 | }; 14 | 15 | // deserialize it with BJData 16 | json j = json::from_bjdata(v); 17 | 18 | // print the deserialized JSON value 19 | std::cout << std::setw(2) << j << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /docs/examples/from_ubjson.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create byte vector 10 | std::vector v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61, 11 | 0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68, 12 | 0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D 13 | }; 14 | 15 | // deserialize it with UBJSON 16 | json j = json::from_ubjson(v); 17 | 18 | // print the deserialized JSON value 19 | std::cout << std::setw(2) << j << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/basic_json/get_allocator.md: -------------------------------------------------------------------------------- 1 | # nlohmann::basic_json::get_allocator 2 | 3 | ```cpp 4 | static allocator_type get_allocator(); 5 | ``` 6 | 7 | Returns the allocator associated with the container. 8 | 9 | ## Return value 10 | 11 | associated allocator 12 | 13 | ## Examples 14 | 15 | ??? example 16 | 17 | The example shows how `get_allocator()` is used to created `json` values. 18 | 19 | ```cpp 20 | --8<-- "examples/get_allocator.cpp" 21 | ``` 22 | 23 | Output: 24 | 25 | ```json 26 | --8<-- "examples/get_allocator.output" 27 | ``` 28 | 29 | ## Version history 30 | 31 | - Added in version 1.0.0. 32 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/boolean.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::boolean 2 | 3 | ```cpp 4 | virtual bool boolean(bool val) = 0; 5 | ``` 6 | 7 | A boolean value was read. 8 | 9 | ## Parameters 10 | 11 | `val` (in) 12 | : boolean value 13 | 14 | ## Return value 15 | 16 | Whether parsing should proceed. 17 | 18 | ## Examples 19 | 20 | ??? example 21 | 22 | The example below shows how the SAX interface is used. 23 | 24 | ```cpp 25 | --8<-- "examples/sax_parse.cpp" 26 | ``` 27 | 28 | Output: 29 | 30 | ```json 31 | --8<-- "examples/sax_parse.output" 32 | ``` 33 | 34 | ## Version history 35 | 36 | - Added in version 3.2.0. 37 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/LoadTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer: find interesting value of array index. 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static volatile int Sink; 12 | const int kArraySize = 1234567; 13 | int array[kArraySize]; 14 | 15 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 16 | if (Size < 8) return 0; 17 | size_t a = 0; 18 | memcpy(&a, Data, 8); 19 | Sink = array[a % (kArraySize + 1)]; 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__parent_pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // different JSON Pointers 9 | json::json_pointer ptr1(""); 10 | json::json_pointer ptr2("/foo"); 11 | json::json_pointer ptr3("/foo/0"); 12 | 13 | // call parent_pointer() 14 | std::cout << std::boolalpha 15 | << "parent of \"" << ptr1 << "\" is \"" << ptr1.parent_pointer() << "\"\n" 16 | << "parent of \"" << ptr2 << "\" is \"" << ptr2.parent_pointer() << "\"\n" 17 | << "parent of \"" << ptr3 << "\" is \"" << ptr3.parent_pointer() << "\"" << std::endl; 18 | } 19 | -------------------------------------------------------------------------------- /docs/examples/unflatten.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create JSON value 10 | json j_flattened = 11 | { 12 | {"/answer/everything", 42}, 13 | {"/happy", true}, 14 | {"/list/0", 1}, 15 | {"/list/1", 0}, 16 | {"/list/2", 2}, 17 | {"/name", "Niels"}, 18 | {"/nothing", nullptr}, 19 | {"/object/currency", "USD"}, 20 | {"/object/value", 42.99}, 21 | {"/pi", 3.141} 22 | }; 23 | 24 | // call unflatten() 25 | std::cout << std::setw(4) << j_flattened.unflatten() << '\n'; 26 | } 27 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__empty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // different JSON Pointers 9 | json::json_pointer ptr0; 10 | json::json_pointer ptr1(""); 11 | json::json_pointer ptr2("/foo"); 12 | json::json_pointer ptr3("/foo/0"); 13 | 14 | // call empty() 15 | std::cout << std::boolalpha 16 | << "\"" << ptr0 << "\": " << ptr0.empty() << '\n' 17 | << "\"" << ptr1 << "\": " << ptr1.empty() << '\n' 18 | << "\"" << ptr2 << "\": " << ptr2.empty() << '\n' 19 | << "\"" << ptr3 << "\": " << ptr3.empty() << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /tests/cmake_add_subdirectory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_test(NAME cmake_add_subdirectory_configure 2 | COMMAND ${CMAKE_COMMAND} 3 | -G "${CMAKE_GENERATOR}" 4 | -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} 5 | -Dnlohmann_json_source=${PROJECT_SOURCE_DIR} 6 | ${CMAKE_CURRENT_SOURCE_DIR}/project 7 | ) 8 | add_test(NAME cmake_add_subdirectory_build 9 | COMMAND ${CMAKE_COMMAND} --build . 10 | ) 11 | set_tests_properties(cmake_add_subdirectory_configure PROPERTIES 12 | FIXTURES_SETUP cmake_add_subdirectory 13 | LABELS not_reproducible 14 | ) 15 | set_tests_properties(cmake_add_subdirectory_build PROPERTIES 16 | FIXTURES_REQUIRED cmake_add_subdirectory 17 | LABELS not_reproducible 18 | ) 19 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/StrncmpOOBTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Test that libFuzzer itself does not read out of bounds. 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static volatile int Sink; 13 | 14 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 15 | if (Size < 5) return 0; 16 | const char *Ch = reinterpret_cast(Data); 17 | if (Ch[Size - 3] == 'a') 18 | Sink = strncmp(Ch + Size - 3, "abcdefg", 6); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/TraceMallocTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Tests -trace_malloc 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int *Ptr; 12 | 13 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 14 | if (!Size) return 0; 15 | if (*Data == 1) { 16 | delete Ptr; 17 | Ptr = nullptr; 18 | } else if (*Data == 2) { 19 | delete Ptr; 20 | Ptr = new int; 21 | } else if (*Data == 3) { 22 | if (!Ptr) 23 | Ptr = new int; 24 | } 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /docs/docset/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | nlohmann_json 7 | CFBundleName 8 | JSON for Modern C++ 9 | DocSetPlatformFamily 10 | json 11 | isDashDocset 12 | 13 | dashIndexFilePath 14 | index.html 15 | DashDocSetFallbackURL 16 | https://nlohmann.github.io/json/ 17 | isJavaScriptEnabled 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/examples/basic_json__list_init_t.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON values 9 | json j_empty_init_list = json({}); 10 | json j_object = { {"one", 1}, {"two", 2} }; 11 | json j_array = {1, 2, 3, 4}; 12 | json j_nested_object = { {"one", {1}}, {"two", {1, 2}} }; 13 | json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} }; 14 | 15 | // serialize the JSON value 16 | std::cout << j_empty_init_list << '\n'; 17 | std::cout << j_object << '\n'; 18 | std::cout << j_array << '\n'; 19 | std::cout << j_nested_object << '\n'; 20 | std::cout << j_nested_array << '\n'; 21 | } 22 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__clear_subtype.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // define a byte container based on std::vector 5 | using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; 6 | 7 | using json = nlohmann::json; 8 | 9 | int main() 10 | { 11 | std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; 12 | 13 | // create container with subtype 14 | auto c1 = byte_container_with_subtype(bytes, 42); 15 | 16 | std::cout << "before calling clear_subtype(): " << json(c1) << '\n'; 17 | 18 | c1.clear_subtype(); 19 | 20 | std::cout << "after calling clear_subtype(): " << json(c1) << '\n'; 21 | } 22 | -------------------------------------------------------------------------------- /docs/examples/get_ref.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON number 9 | json value = 17; 10 | 11 | // explicitly getting references 12 | auto r1 = value.get_ref(); 13 | auto r2 = value.get_ref(); 14 | 15 | // print the values 16 | std::cout << r1 << ' ' << r2 << '\n'; 17 | 18 | // incompatible type throws exception 19 | try 20 | { 21 | auto r3 = value.get_ref(); 22 | } 23 | catch (const json::type_error& ex) 24 | { 25 | std::cout << ex.what() << '\n'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/number_integer.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::number_integer 2 | 3 | ```cpp 4 | virtual bool number_integer(number_integer_t val) = 0; 5 | ``` 6 | 7 | An integer number was read. 8 | 9 | ## Parameters 10 | 11 | `val` (in) 12 | : integer value 13 | 14 | ## Return value 15 | 16 | Whether parsing should proceed. 17 | 18 | ## Examples 19 | 20 | ??? example 21 | 22 | The example below shows how the SAX interface is used. 23 | 24 | ```cpp 25 | --8<-- "examples/sax_parse.cpp" 26 | ``` 27 | 28 | Output: 29 | 30 | ```json 31 | --8<-- "examples/sax_parse.output" 32 | ``` 33 | 34 | ## Version history 35 | 36 | - Added in version 3.2.0. 37 | -------------------------------------------------------------------------------- /tests/cmake_import_minver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_test(NAME cmake_import_minver_configure 2 | COMMAND ${CMAKE_COMMAND} 3 | -G "${CMAKE_GENERATOR}" 4 | -A "${CMAKE_GENERATOR_PLATFORM}" 5 | -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} 6 | -Dnlohmann_json_DIR=${PROJECT_BINARY_DIR} 7 | ${CMAKE_CURRENT_SOURCE_DIR}/project 8 | ) 9 | add_test(NAME cmake_import_minver_build 10 | COMMAND ${CMAKE_COMMAND} --build . 11 | ) 12 | set_tests_properties(cmake_import_minver_configure PROPERTIES 13 | FIXTURES_SETUP cmake_import_minver 14 | LABELS not_reproducible 15 | ) 16 | set_tests_properties(cmake_import_minver_build PROPERTIES 17 | FIXTURES_REQUIRED cmake_import_minver 18 | LABELS not_reproducible 19 | ) 20 | -------------------------------------------------------------------------------- /wsjcpp.yml: -------------------------------------------------------------------------------- 1 | wsjcpp_version: "v0.1.1" 2 | cmake_minimum_required: "3.0" 3 | cmake_cxx_standard: "11" 4 | name: "nlohmann/json" 5 | version: "v3.11.3" 6 | description: "JSON for Modern C++" 7 | issues: "https://github.com/nlohmann/json/issues" 8 | keywords: 9 | - "c++" 10 | - "json" 11 | 12 | repositories: 13 | - type: main 14 | url: "https://github.com/nlohmann/json" 15 | 16 | authors: 17 | - name: "Niels Lohmann" 18 | email: "mail@nlohmann.me" 19 | 20 | distribution: 21 | - source-file: "single_include/nlohmann/json.hpp" 22 | target-file: "json.hpp" 23 | type: "source-code" 24 | - source-file: "single_include/nlohmann/json_fwd.hpp" 25 | target-file: "json_fwd.hpp" 26 | type: "source-code" 27 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__has_subtype.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // define a byte container based on std::vector 5 | using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; 6 | 7 | int main() 8 | { 9 | std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; 10 | 11 | // create container 12 | auto c1 = byte_container_with_subtype(bytes); 13 | 14 | // create container with subtype 15 | auto c2 = byte_container_with_subtype(bytes, 42); 16 | 17 | std::cout << std::boolalpha << "c1.has_subtype() = " << c1.has_subtype() 18 | << "\nc2.has_subtype() = " << c2.has_subtype() << std::endl; 19 | } 20 | -------------------------------------------------------------------------------- /docs/examples/push_back__object_t__value.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create JSON values 9 | json object = {{"one", 1}, {"two", 2}}; 10 | json null; 11 | 12 | // print values 13 | std::cout << object << '\n'; 14 | std::cout << null << '\n'; 15 | 16 | // add values 17 | object.push_back(json::object_t::value_type("three", 3)); 18 | object += json::object_t::value_type("four", 4); 19 | null += json::object_t::value_type("A", "a"); 20 | null += json::object_t::value_type("B", "b"); 21 | 22 | // print values 23 | std::cout << object << '\n'; 24 | std::cout << null << '\n'; 25 | } 26 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/ordered_json.md: -------------------------------------------------------------------------------- 1 | # nlohmann::ordered_json 2 | 3 | ```cpp 4 | using ordered_json = basic_json; 5 | ``` 6 | 7 | This type preserves the insertion order of object keys. 8 | 9 | ## Examples 10 | 11 | ??? example 12 | 13 | The example below demonstrates how `ordered_json` preserves the insertion order of object keys. 14 | 15 | ```cpp 16 | --8<-- "examples/ordered_json.cpp" 17 | ``` 18 | 19 | Output: 20 | 21 | ```json 22 | --8<-- "examples/ordered_json.output" 23 | ``` 24 | 25 | ## See also 26 | 27 | - [ordered_map](ordered_map.md) 28 | - [Object Order](../features/object_order.md) 29 | 30 | ## Version history 31 | 32 | Since version 3.9.0. 33 | -------------------------------------------------------------------------------- /include/nlohmann/detail/meta/void_t.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.11.3 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | namespace detail 15 | { 16 | 17 | template struct make_void 18 | { 19 | using type = void; 20 | }; 21 | template using void_t = typename make_void::type; 22 | 23 | } // namespace detail 24 | NLOHMANN_JSON_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/AbsNegAndConstantTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // abs(x) < 0 and y == Const puzzle. 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 12 | if (Size < 8) return 0; 13 | int x; 14 | unsigned y; 15 | memcpy(&x, Data, sizeof(x)); 16 | memcpy(&y, Data + sizeof(x), sizeof(y)); 17 | if (abs(x) < 0 && y == 0xbaddcafe) { 18 | printf("BINGO; Found the target, exiting; x = 0x%x y 0x%x\n", x, y); 19 | exit(1); 20 | } 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /docs/examples/byte_container_with_subtype__set_subtype.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // define a byte container based on std::vector 5 | using byte_container_with_subtype = nlohmann::byte_container_with_subtype>; 6 | 7 | using json = nlohmann::json; 8 | 9 | int main() 10 | { 11 | std::vector bytes = {{0xca, 0xfe, 0xba, 0xbe}}; 12 | 13 | // create container without subtype 14 | auto c = byte_container_with_subtype(bytes); 15 | 16 | std::cout << "before calling set_subtype(42): " << json(c) << '\n'; 17 | 18 | // set the subtype 19 | c.set_subtype(42); 20 | 21 | std::cout << "after calling set_subtype(42): " << json(c) << '\n'; 22 | } 23 | -------------------------------------------------------------------------------- /docs/examples/dump.output: -------------------------------------------------------------------------------- 1 | objects: 2 | {"one":1,"two":2} 3 | 4 | {"one":1,"two":2} 5 | 6 | { 7 | "one": 1, 8 | "two": 2 9 | } 10 | 11 | { 12 | "one": 1, 13 | "two": 2 14 | } 15 | 16 | { 17 | "one": 1, 18 | "two": 2 19 | } 20 | 21 | arrays: 22 | [1,2,4,8,16] 23 | 24 | [1,2,4,8,16] 25 | 26 | [ 27 | 1, 28 | 2, 29 | 4, 30 | 8, 31 | 16 32 | ] 33 | 34 | [ 35 | 1, 36 | 2, 37 | 4, 38 | 8, 39 | 16 40 | ] 41 | 42 | [ 43 | 1, 44 | 2, 45 | 4, 46 | 8, 47 | 16 48 | ] 49 | 50 | strings: 51 | "Hellö 😀!" 52 | "Hell\u00f6 \ud83d\ude00!" 53 | [json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9 54 | string with replaced invalid characters: "ä�ü" 55 | string with ignored invalid characters: "äü" 56 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_pointer/string_t.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_pointer::string_t 2 | ```cpp 3 | using string_t = RefStringType; 4 | ``` 5 | 6 | The string type used for the reference tokens making up the JSON pointer. 7 | 8 | See [`basic_json::string_t`](../basic_json/string_t.md) for more information. 9 | 10 | ## Examples 11 | 12 | ??? example 13 | 14 | The example shows the type `string_t` and its relation to `basic_json::string_t`. 15 | 16 | ```cpp 17 | --8<-- "examples/json_pointer__string_t.cpp" 18 | ``` 19 | 20 | Output: 21 | 22 | ```json 23 | --8<-- "examples/json_pointer__string_t.output" 24 | ``` 25 | 26 | ## Version history 27 | 28 | - Added in version 3.11.0. 29 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/number_unsigned.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::number_unsigned 2 | 3 | ```cpp 4 | virtual bool number_unsigned(number_unsigned_t val) = 0; 5 | ``` 6 | 7 | An unsigned integer number was read. 8 | 9 | ## Parameters 10 | 11 | `val` (in) 12 | : unsigned integer value 13 | 14 | ## Return value 15 | 16 | Whether parsing should proceed. 17 | 18 | ## Examples 19 | 20 | ??? example 21 | 22 | The example below shows how the SAX interface is used. 23 | 24 | ```cpp 25 | --8<-- "examples/sax_parse.cpp" 26 | ``` 27 | 28 | Output: 29 | 30 | ```json 31 | --8<-- "examples/sax_parse.output" 32 | ``` 33 | 34 | ## Version history 35 | 36 | - Added in version 3.2.0. 37 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('nlohmann_json', 2 | 'cpp', 3 | version : '3.11.3', 4 | license : 'MIT', 5 | ) 6 | 7 | nlohmann_json_dep = declare_dependency( 8 | include_directories: include_directories('single_include') 9 | ) 10 | 11 | nlohmann_json_multiple_headers = declare_dependency( 12 | include_directories: include_directories('include') 13 | ) 14 | 15 | if not meson.is_subproject() 16 | install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') 17 | install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann') 18 | 19 | pkgc = import('pkgconfig') 20 | pkgc.generate(name: 'nlohmann_json', 21 | version: meson.project_version(), 22 | description: 'JSON for Modern C++' 23 | ) 24 | endif 25 | -------------------------------------------------------------------------------- /docs/examples/find__keytype.c++17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std::string_view_literals; 6 | using json = nlohmann::json; 7 | 8 | int main() 9 | { 10 | // create a JSON object 11 | json j_object = {{"one", 1}, {"two", 2}}; 12 | 13 | // call find 14 | auto it_two = j_object.find("two"sv); 15 | auto it_three = j_object.find("three"sv); 16 | 17 | // print values 18 | std::cout << std::boolalpha; 19 | std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n'; 20 | std::cout << "value at key \"two\": " << *it_two << '\n'; 21 | std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n'; 22 | } 23 | -------------------------------------------------------------------------------- /docs/examples/from_bson.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create byte vector 10 | std::vector v = {0x1b, 0x00, 0x00, 0x00, 0x08, 0x63, 0x6f, 0x6d, 11 | 0x70, 0x61, 0x63, 0x74, 0x00, 0x01, 0x10, 0x73, 12 | 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00, 0x00, 0x00, 13 | 0x00, 0x00, 0x00 14 | }; 15 | 16 | // deserialize it with BSON 17 | json j = json::from_bson(v); 18 | 19 | // print the deserialized JSON value 20 | std::cout << std::setw(2) << j << std::endl; 21 | } 22 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/integration/index.md: -------------------------------------------------------------------------------- 1 | # Header only 2 | 3 | [`json.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp) is the single required 4 | file in `single_include/nlohmann` or [released here](https://github.com/nlohmann/json/releases). You need to add 5 | 6 | ```cpp 7 | #include 8 | 9 | // for convenience 10 | using json = nlohmann::json; 11 | ``` 12 | 13 | to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and 14 | Clang). 15 | 16 | You can further use file 17 | [`single_include/nlohmann/json_fwd.hpp`](https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json_fwd.hpp) 18 | for forward declarations. 19 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/AFLDriverTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Contains dummy functions used to avoid dependency on AFL. 5 | #include 6 | #include 7 | 8 | extern "C" void __afl_manual_init() {} 9 | 10 | extern "C" int __afl_persistent_loop(unsigned int) { 11 | return 0; 12 | } 13 | 14 | // This declaration exists to prevent the Darwin linker 15 | // from complaining about this being a missing weak symbol. 16 | extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { 17 | return 0; 18 | } 19 | 20 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/BufferOverflowOnInput.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer. The fuzzer must find the string "Hi!". 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static volatile bool SeedLargeBuffer; 12 | 13 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 14 | assert(Data); 15 | if (Size >= 4) 16 | SeedLargeBuffer = true; 17 | if (Size == 3 && SeedLargeBuffer && Data[3]) { 18 | std::cout << "Woops, reading Data[3] w/o crashing\n"; 19 | exit(1); 20 | } 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/TimeoutTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Simple test for a fuzzer. The fuzzer must find the string "Hi!". 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static volatile int Sink; 11 | 12 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 13 | if (Size > 0 && Data[0] == 'H') { 14 | Sink = 1; 15 | if (Size > 1 && Data[1] == 'i') { 16 | Sink = 2; 17 | if (Size > 2 && Data[2] == '!') { 18 | Sink = 2; 19 | while (Sink) 20 | ; 21 | } 22 | } 23 | } 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /docs/examples/get_ptr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // create a JSON number 9 | json value = 17; 10 | 11 | // explicitly getting pointers 12 | auto p1 = value.get_ptr(); 13 | auto p2 = value.get_ptr(); 14 | auto p3 = value.get_ptr(); 15 | auto p4 = value.get_ptr(); 16 | auto p5 = value.get_ptr(); 17 | 18 | // print the pointees 19 | std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n'; 20 | std::cout << std::boolalpha << (p5 == nullptr) << '\n'; 21 | } 22 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_pointer/pop_back.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_pointer::pop_back 2 | 3 | ```cpp 4 | void pop_back(); 5 | ``` 6 | 7 | Remove last reference token. 8 | 9 | ## Exceptions 10 | 11 | Throws [out_of_range.405](../../home/exceptions.md#jsonexceptionout_of_range405) if JSON pointer has no parent. 12 | 13 | ## Complexity 14 | 15 | Constant. 16 | 17 | ## Examples 18 | 19 | ??? example 20 | 21 | The example shows the usage of `pop_back`. 22 | 23 | ```cpp 24 | --8<-- "examples/json_pointer__pop_back.cpp" 25 | ``` 26 | 27 | Output: 28 | 29 | ```json 30 | --8<-- "examples/json_pointer__pop_back.output" 31 | ``` 32 | 33 | ## Version history 34 | 35 | Added in version 3.6.0. 36 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/key.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::key 2 | 3 | ```cpp 4 | virtual bool key(string_t& val) = 0; 5 | ``` 6 | 7 | An object key was read. 8 | 9 | ## Parameters 10 | 11 | `val` (in) 12 | : object key 13 | 14 | ## Return value 15 | 16 | Whether parsing should proceed. 17 | 18 | ## Notes 19 | 20 | It is safe to move the passed object key value. 21 | 22 | ## Examples 23 | 24 | ??? example 25 | 26 | The example below shows how the SAX interface is used. 27 | 28 | ```cpp 29 | --8<-- "examples/sax_parse.cpp" 30 | ``` 31 | 32 | Output: 33 | 34 | ```json 35 | --8<-- "examples/sax_parse.output" 36 | ``` 37 | 38 | ## Version history 39 | 40 | - Added in version 3.2.0. 41 | -------------------------------------------------------------------------------- /docs/examples/contains__keytype.c++17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std::string_view_literals; 6 | using json = nlohmann::json; 7 | using namespace nlohmann::literals; 8 | 9 | int main() 10 | { 11 | // create some JSON values 12 | json j_object = R"( {"key": "value"} )"_json; 13 | json j_array = R"( [1, 2, 3] )"_json; 14 | 15 | // call contains 16 | std::cout << std::boolalpha << 17 | "j_object contains 'key': " << j_object.contains("key"sv) << '\n' << 18 | "j_object contains 'another': " << j_object.contains("another"sv) << '\n' << 19 | "j_array contains 'key': " << j_array.contains("key"sv) << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /tests/thirdparty/Fuzzer/test/ShrinkValueProfileTest.cpp: -------------------------------------------------------------------------------- 1 | // This file is distributed under the University of Illinois Open Source 2 | // License. See LICENSE.TXT for details. 3 | 4 | // Test that we can find the minimal item in the corpus (3 bytes: "FUZ"). 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static volatile uint32_t Sink; 12 | 13 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 14 | if (Size < sizeof(uint32_t)) return 0; 15 | uint32_t X, Y; 16 | size_t Offset = Size < 8 ? 0 : Size / 2; 17 | memcpy(&X, Data + Offset, sizeof(uint32_t)); 18 | memcpy(&Y, "FUZZ", sizeof(uint32_t)); 19 | Sink = X == Y; 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /docs/mkdocs/docs/api/json_sax/string.md: -------------------------------------------------------------------------------- 1 | # nlohmann::json_sax::string 2 | 3 | ```cpp 4 | virtual bool string(string_t& val) = 0; 5 | ``` 6 | 7 | A string value was read. 8 | 9 | ## Parameters 10 | 11 | `val` (in) 12 | : string value 13 | 14 | ## Return value 15 | 16 | Whether parsing should proceed. 17 | 18 | ## Notes 19 | 20 | It is safe to move the passed string value. 21 | 22 | ## Examples 23 | 24 | ??? example 25 | 26 | The example below shows how the SAX interface is used. 27 | 28 | ```cpp 29 | --8<-- "examples/sax_parse.cpp" 30 | ``` 31 | 32 | Output: 33 | 34 | ```json 35 | --8<-- "examples/sax_parse.output" 36 | ``` 37 | 38 | ## Version history 39 | 40 | - Added in version 3.2.0. 41 | -------------------------------------------------------------------------------- /docs/examples/flatten.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using json = nlohmann::json; 6 | 7 | int main() 8 | { 9 | // create JSON value 10 | json j = 11 | { 12 | {"pi", 3.141}, 13 | {"happy", true}, 14 | {"name", "Niels"}, 15 | {"nothing", nullptr}, 16 | { 17 | "answer", { 18 | {"everything", 42} 19 | } 20 | }, 21 | {"list", {1, 0, 2}}, 22 | { 23 | "object", { 24 | {"currency", "USD"}, 25 | {"value", 42.99} 26 | } 27 | } 28 | }; 29 | 30 | // call flatten() 31 | std::cout << std::setw(4) << j.flatten() << '\n'; 32 | } 33 | -------------------------------------------------------------------------------- /docs/examples/json_pointer__operator__equal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using json = nlohmann::json; 5 | 6 | int main() 7 | { 8 | // different JSON pointers 9 | json::json_pointer ptr0; 10 | json::json_pointer ptr1(""); 11 | json::json_pointer ptr2("/foo"); 12 | 13 | // compare JSON pointers 14 | std::cout << std::boolalpha 15 | << "\"" << ptr0 << "\" == \"" << ptr0 << "\": " << (ptr0 == ptr0) << '\n' 16 | << "\"" << ptr0 << "\" == \"" << ptr1 << "\": " << (ptr0 == ptr1) << '\n' 17 | << "\"" << ptr1 << "\" == \"" << ptr2 << "\": " << (ptr1 == ptr2) << '\n' 18 | << "\"" << ptr2 << "\" == \"" << ptr2 << "\": " << (ptr2 == ptr2) << std::endl; 19 | } 20 | --------------------------------------------------------------------------------