1
0
mirror of https://github.com/nlohmann/json.git synced 2026-07-22 11:43:02 +04:00

Compare commits

..

1480 Commits

Author SHA1 Message Date
Niels Lohmann f642934b18 🔀 merge branch 'release/2.1.0' into develop 2017-01-28 18:43:01 +01:00
Niels Lohmann 6746a57524 📝 updated slides 2017-01-28 18:41:30 +01:00
Niels Lohmann eb08e8b09b 📝 updated documentation 2017-01-28 18:20:12 +01:00
Niels Lohmann 4b5c61075f 📄 changes to let Github detect the license 2017-01-28 18:17:57 +01:00
Niels Lohmann 38e4935db0 📝 added example and documentation for the meta function 2017-01-28 17:12:29 +01:00
Niels Lohmann cdde1a9436 🔖 set version to 2.1.0 2017-01-28 16:46:03 +01:00
Niels Lohmann d870826811 🔖 set version to 2.1.0 2017-01-28 16:03:35 +01:00
Niels Lohmann 2f6260751c 📝 fixed #434 2017-01-27 18:50:52 +01:00
Niels Lohmann 42fa3f0568 🔀 merge pull request #435 (based on #338, #355, and #423)
conversion from/to user-defined types
2017-01-27 06:22:10 +01:00
Niels Lohmann cd9701b123 💄 cleanup 2017-01-26 20:51:30 +01:00
Niels Lohmann 1305e03557 📝 fixed documentation 2017-01-26 19:39:34 +01:00
Niels Lohmann 77bb7af5d9 📝 added more documentation 2017-01-26 07:29:37 +01:00
Niels Lohmann 4d3053cd42 💄 some cleanup 2017-01-25 22:21:07 +01:00
Niels Lohmann 94d9b7bc86 📝 overworked documentation (re-added constructor examples) 2017-01-25 21:59:54 +01:00
Niels Lohmann ec03c9c53e 📝 overworked docs #435 2017-01-25 19:01:31 +01:00
Niels Lohmann 4139bb6572 📝 adjusted test count 2017-01-24 15:20:20 +01:00
Niels Lohmann c154f3133d 🚧 rephrased assertions 2017-01-24 15:02:35 +01:00
Niels Lohmann 50a3f3b301 📝 added nicer example 2017-01-24 14:55:51 +01:00
Niels Lohmann 781fd09f2d 📝 cleanup 2017-01-24 14:45:32 +01:00
Niels Lohmann daf8dcdb32 📝 overworked README 2017-01-24 14:37:25 +01:00
Niels Lohmann 250e5bf43d 💄 overworked documentation and indentation 2017-01-24 13:47:33 +01:00
Niels Lohmann 030cf674ef 🚧 fixed a warning 2017-01-24 12:49:38 +01:00
Niels Lohmann 3857e55290 💄 ran "make pretty" 2017-01-24 12:43:43 +01:00
Théo DELRIEU 9f103d19d7 add implicit conversions test (operator T()) 2017-01-22 14:23:24 +01:00
Théo DELRIEU 9f8b270ed9 fix some warnings 2017-01-22 14:07:28 +01:00
Théo DELRIEU 9c6ef74a28 add static_asserts/remove the need for CopyConstructible in get 2017-01-21 19:12:40 +01:00
Théo DELRIEU ba0b35f414 use typename U = uncvref_t where appropriate 2017-01-21 19:12:40 +01:00
Théo DELRIEU 37fd20b2eb put uncvref_t, enable_if_t, value_t and operator<(value_t) in detail 2017-01-21 19:12:40 +01:00
Théo DELRIEU 7d771c71ed put back type_name in basic_json
This can however not be done easily for value_t, since
external_constructor depends on it, as is operator< which was moved
outside basic_json too.
This is not really an issue, since all basic_json classes share the same
enum
2017-01-21 19:12:40 +01:00
Théo DELRIEU f997758cad remove useless forward declaration of primitive_iterator_t 2017-01-21 19:12:40 +01:00
Théo DELRIEU 40ba5a8b7b remove inline keyword from anonymous namespace (not needed) 2017-01-21 19:12:40 +01:00
Théo DELRIEU 7f359017d2 rename template argument Json -> BasicJsonType 2017-01-21 19:12:40 +01:00
Théo DELRIEU 708eb9613b disable reserve tests when exceptions are disabled 2017-01-21 19:12:40 +01:00
Théo DELRIEU 889b269a4f rename template argument: BasicJson -> Json 2017-01-21 16:14:23 +01:00
Théo DELRIEU a6b028286b move conjunction/disjunction to the top of detail 2017-01-21 16:14:23 +01:00
Théo DELRIEU d566bb81c4 use switchs where appropriate 2017-01-21 16:14:23 +01:00
Théo DELRIEU 1e20887cff use JSON_THROW 2017-01-21 16:14:22 +01:00
Théo DELRIEU 447c6a670f run make re2c 2017-01-21 16:14:22 +01:00
Théo DELRIEU 3e15b551e0 run make pretty 2017-01-21 16:14:22 +01:00
Théo DELRIEU fbac056c38 add readme 2017-01-21 16:14:22 +01:00
Théo DELRIEU b56117b148 add noexcept tests 2017-01-21 16:14:22 +01:00
Théo DELRIEU af94e712c7 add basic doxygen documentations 2017-01-21 16:14:22 +01:00
Théo DELRIEU 1d87097741 remove some boilerplate 2017-01-21 16:14:22 +01:00
Théo DELRIEU e60e458a7e move static_const to the detail namespace 2017-01-21 16:14:22 +01:00
Théo DELRIEU 794dae8911 apply changes to json.hpp.re2c 2017-01-21 16:14:22 +01:00
Théo DELRIEU 68081cd112 remove useless file 2017-01-21 16:14:22 +01:00
Théo DELRIEU 07bc82d3a7 put const to the left 2017-01-21 16:14:22 +01:00
Théo DELRIEU f1482d1f01 more tests in unit-udt 2017-01-21 16:14:22 +01:00
Théo DELRIEU f2c71fafda minor message/comments tweak 2017-01-21 16:14:22 +01:00
Théo DELRIEU 63e4249e9f use a priority_tag instead of int and longs with sfinae-dispatch 2017-01-21 16:14:22 +01:00
Théo DELRIEU b8012876a5 add noexcept checks, and some missing noexcepts 2017-01-21 16:14:22 +01:00
Théo DELRIEU 1554baa01d attempting to fix coverage. testing that reserve is called 2017-01-21 16:14:22 +01:00
Théo DELRIEU a9d5ae4fad put back a specialization for containers with a reserve method 2017-01-21 16:14:22 +01:00
Théo DELRIEU e247e01a6e use static_casts to silence MSVC warnings
Those warnings are not "fixed", but that's intentional.
Truncations are expected when ArithmeticType is not the same type than
number_unsigned_t (or another basic_json template argument)
2017-01-21 16:14:22 +01:00
Théo DELRIEU d0d8070422 add static_asserts
remove some useless trailing return types and && to help MSVC
2017-01-21 16:14:22 +01:00
Théo DELRIEU e678c075dd check for is_number_unsigned before is_number_integer 2017-01-21 16:14:22 +01:00
Théo DELRIEU cb3d455bd2 do not const_cast when calling get_ptr 2017-01-21 16:14:22 +01:00
Théo DELRIEU 3494014ba0 new unit-udt.cpp tests 2017-01-21 16:14:22 +01:00
Théo DELRIEU 1f25ec5d36 add some constexpr + noexcept 2017-01-21 16:14:22 +01:00
Théo DELRIEU 29f9fe6ae9 remove one has_to/from_json template parameter 2017-01-21 16:14:22 +01:00
Théo DELRIEU 5839795725 remove useless helpers 2017-01-21 16:14:22 +01:00
Théo DELRIEU b4cea6825d remove is_compatible_array_type_impl trait 2017-01-21 16:14:22 +01:00
Théo DELRIEU b2543e06d8 removed is_compatible_float_type trait 2017-01-21 16:14:22 +01:00
Théo DELRIEU be6b417c87 tweak SFINAE checks for internal types (see commit body)
only check for public types (iterators, json_pointer)

for private ones (m_array.iterator, primitive_iterator) simply double
parentheses on relevant Catch checks
2017-01-21 16:14:22 +01:00
Théo DELRIEU 317883b21b cleanup, details in body
removes:
- is_basic_json_compatible_type traits
- a useless operator=
- void_t
- disjunction

changes:
- is_compatible_object_type's first argument is BasicJson
2017-01-21 16:14:22 +01:00
Théo DELRIEU 4e8089b9de remove old get/get_impl overloads (doc removal is of course temporary) 2017-01-21 16:14:22 +01:00
Théo DELRIEU 7e6a6f978e replace constructor by from/to_json: array_t 2017-01-21 16:14:22 +01:00
Théo DELRIEU c847e0eea2 replace constructor by from/to_json: array_t
- tweaked a bit how `get<container<json>>` is handled
- added a from_json overload for forward list
2017-01-21 16:14:22 +01:00
Théo DELRIEU 6d427acdde replace constructor by from/to_json: unscoped enum types
this also means that one can do: j.get<unscoped_enum>();
2017-01-21 16:14:22 +01:00
Théo DELRIEU f00898331e replace constructor by from/to_json: number_integer_t 2017-01-21 16:14:22 +01:00
Théo DELRIEU a32de3b528 replace constructor by from/to_json: number_unsigned_t
This commit forces a design change in custom JSONSerializer, which might
be temporary
2017-01-21 16:14:21 +01:00
Théo DELRIEU d257149f36 replace constructor by from/to_json: number_float_t 2017-01-21 16:14:21 +01:00
Théo DELRIEU bbe40641a3 replace constructor by from/to_json: string_t 2017-01-21 16:14:21 +01:00
Théo DELRIEU 6b89785fba replace constructor by from/to_json: boolean_t 2017-01-21 16:14:21 +01:00
Théo DELRIEU c833b22b7b move type_name outside of basic_json, make it a friend 2017-01-21 16:14:21 +01:00
Théo DELRIEU d359684f2b move enum class value_t outside of basic_json 2017-01-21 16:14:21 +01:00
Niels Lohmann 034d5ed97e 💄 some cleanup 2017-01-21 16:14:21 +01:00
Niels Lohmann be1d3de49b 💄 moved changes to re2c file and ran make pretty 2017-01-21 16:14:21 +01:00
Théo DELRIEU aa2679a8ce fix tests, avoid instantiating JSONSerializer when it will not be used 2017-01-21 16:14:21 +01:00
Théo DELRIEU d5ee5830ed add more tests 2017-01-21 16:14:21 +01:00
Théo DELRIEU 1c21c87e6f use u8 prefix in unit-udt.cpp 2017-01-21 16:14:21 +01:00
Théo DELRIEU 7e750ec1fa fix msvc, by doubling parenthesis on catch assertions 2017-01-21 16:14:21 +01:00
Théo DELRIEU 3d405c6883 add support for enum classes 2017-01-21 16:14:21 +01:00
Théo DELRIEU 8e43d476d3 add more tests to unit-udt.cpp 2017-01-21 16:14:21 +01:00
Théo DELRIEU f5cb089f89 add an enum constructor (quickfix) 2017-01-21 16:14:21 +01:00
Théo DELRIEU 1eafac7220 remove explicit keyword on udt-constructor 2017-01-21 16:14:21 +01:00
Théo Delrieu c0c72b5b62 rewrite unit-udt: basic usage 2017-01-21 16:14:21 +01:00
Théo DELRIEU 60e6f822fa add support for non-default-constructible udt 2017-01-21 16:14:21 +01:00
Théo DELRIEU e5999c6c82 add a few tests 2017-01-21 16:14:21 +01:00
Théo Delrieu 74bb11d92c remove some useless checks, format a bit, added some comments 2017-01-21 16:14:21 +01:00
Théo DELRIEU 907484fb43 format biggest lines 2017-01-21 16:14:21 +01:00
Théo Delrieu 47bc402113 only use conjunction & co when needed to avoid MSVC crashing 2017-01-21 16:14:21 +01:00
Théo DELRIEU ee19acaf05 add is_compatible_basic_json_type trait 2017-01-21 16:14:21 +01:00
Théo Delrieu 9b401972a0 add a macro for has_xxx types 2017-01-21 16:14:21 +01:00
Théo DELRIEU e2dbe7a69f correctly constrain basic_json udt constructor 2017-01-21 16:14:21 +01:00
Théo DELRIEU 0d91113ccf add negation, disjunction, and conjunction from C++17 2017-01-21 16:14:21 +01:00
Théo DELRIEU 88819449c2 remove constraints on JSONSerializer instances, constrain correctly new methods 2017-01-21 16:14:21 +01:00
Théo DELRIEU 23bd2bce35 add is_compatible_* traits 2017-01-21 16:14:21 +01:00
Théo DELRIEU 178441cdfd add basic test for custom serializer 2017-01-21 16:14:21 +01:00
Théo DELRIEU 2bc685f6b4 to_json and from_json takes both two arguments now
the first is the basic_json type, the second the user-defined type
2017-01-21 16:14:21 +01:00
Théo DELRIEU 837b81d672 renamed unit-constructor3.cpp to unit-udt.cpp 2017-01-21 16:14:21 +01:00
Théo DELRIEU 33abccf847 add template arguments for JSONSerializer 2017-01-21 16:14:21 +01:00
Théo DELRIEU 7dc268ef42 add first version for alternate implementation 2017-01-21 16:14:21 +01:00
Théo DELRIEU 4cdc61e493 move most SFINAE trickery in to/from_json_fn 2017-01-21 16:14:21 +01:00
Théo DELRIEU 03b391c37b remove has_destructor and has_json_traits, use decltype instead 2017-01-21 16:14:21 +01:00
Théo DELRIEU 12b4555b13 use uncvref_t<T> instead of remove_cv_t<remove_reference_t<T>>> 2017-01-21 16:14:21 +01:00
Théo DELRIEU 877d96c1d8 rename __static_const to _static_const (reserved identifier) 2017-01-21 16:14:21 +01:00
Théo DELRIEU d54d6bb84c add alias templates to reduce boilerplate 2017-01-21 16:14:21 +01:00
Théo DELRIEU fe628b585b anonymous namespace renamed to detail 2017-01-21 16:14:21 +01:00
Théo Delrieu b443edf49e add first version support for user-defined types 2017-01-21 16:14:20 +01:00
Niels Lohmann ce0b3fe5a3 🚧 made type_name() public 2017-01-21 16:12:17 +01:00
Niels Lohmann 145188f264 renaming did not help 2017-01-19 19:23:56 +01:00
Niels Lohmann 69be3fa842 📝 small documentation update 2017-01-19 18:19:20 +01:00
Niels Lohmann 5e3f9c8969 📄 help Github find the license 2017-01-19 17:09:55 +01:00
Niels Lohmann e951d198f4 🔀 merge pull request #430 from vjon/patch-1
Fix documentation error
2017-01-19 07:42:29 +01:00
Jonathan Lee 046f6da82f Fix documentation error
Move comparison before "j.clear()" function call, such that the intended return value "true" is actually correct.
2017-01-18 11:43:14 -08:00
Niels Lohmann bae8e70137 🔀 merge branch 'feature/noexceptions_2' into develop 2017-01-18 20:41:17 +01:00
Niels Lohmann 87c5e32e1f 🐛 fixed escaping 2017-01-16 22:46:49 +01:00
Niels Lohmann a00149f8ee 🐛 fixed logic error 2017-01-16 22:36:58 +01:00
Niels Lohmann 1ab26ab367 option to switch off exceptions 2017-01-16 22:11:07 +01:00
Niels Lohmann 74cbd30cd0 📄 it's 2017 2017-01-16 20:04:47 +01:00
Niels Lohmann a7f3938391 added Big List of Naughty Strings 2017-01-16 20:03:50 +01:00
Niels Lohmann a9b4cb8bf8 🔀 merge branch 'feature/release_information' into develop #397 2017-01-12 21:37:31 +01:00
Niels Lohmann 3a9ccfac22 🚧 cleanup 2017-01-12 21:35:27 +01:00
Niels Lohmann 98ad3c3ac1 Merge branch 'develop' into feature/release_information 2017-01-12 21:30:08 +01:00
Niels Lohmann 0f03543861 ⬆️ upgraded to Catch 1.6.0 2017-01-11 22:23:02 +01:00
Niels Lohmann e9bbf5aaba 🐛 forgot to remove a test case 2017-01-08 09:31:40 +01:00
Niels Lohmann dd45ba6f89 🚧 renamed version() to meta() 2017-01-08 09:19:44 +01:00
Niels Lohmann e1b89dd1d6 Merge branch 'develop' into feature/release_information 2017-01-04 20:06:23 +01:00
Niels Lohmann 9f6c86f233 🐛 fix for #417 2017-01-04 18:54:44 +01:00
Niels Lohmann 4765070318 📝 added documentation wrt. UTF-8 strings #406 2017-01-04 18:07:46 +01:00
Niels Lohmann cdd3b5a68c 🚑 fix for #416 2017-01-03 23:52:01 +01:00
Niels Lohmann 767637877b 💄 cleanup 2017-01-03 22:37:07 +01:00
Niels Lohmann f8d640b185 👷 better support for OSS-Fuzz 2017-01-03 22:35:31 +01:00
Niels Lohmann 245a69d554 💄 ran clang-tidy 2017-01-03 21:33:23 +01:00
Niels Lohmann ea4d71ee21 Merge branch 'develop' into feature/release_information 2017-01-02 17:26:00 +01:00
Niels Lohmann 9755cc75b1 🔀 merge branch 'release/2.0.10' into develop 2017-01-02 16:38:23 +01:00
Niels Lohmann 7e2c4b3ead 📝 updated online link 2017-01-02 16:37:29 +01:00
Niels Lohmann 69c615e127 🔖 version bump to 2.0.10 2017-01-02 10:00:44 +01:00
Niels Lohmann 4d3bf433b4 🔖 updated ChangeLog 2017-01-02 09:56:21 +01:00
Niels Lohmann 8b46eb8ec0 📄 it's 2017 already 2017-01-02 09:40:00 +01:00
Niels Lohmann 6a20790056 📝 updated test count 2017-01-02 09:36:30 +01:00
Niels Lohmann 60b3703c62 🔖 version bump to 2.0.10 2017-01-02 09:35:57 +01:00
Niels Lohmann d173517212 💄 clean up 2017-01-02 09:21:26 +01:00
Niels Lohmann a3063c2419 🚧 added target to build all fuzzers 2017-01-01 21:51:36 +01:00
Niels Lohmann db33629990 💄 cleanup after #410 2017-01-01 21:34:58 +01:00
Niels Lohmann 712529cd32 🔀 merge pull request #400 from andoma/develop
Add Doozer build badge
2017-01-01 19:47:33 +01:00
Niels Lohmann 09b91406c6 🔀 merge pull request #410 from Daniel599/feature/clang_sanitize
Feature/clang sanitize
2017-01-01 19:45:11 +01:00
Niels Lohmann ab7d55e7ae 👷 removed failing test suites 2017-01-01 19:38:54 +01:00
Niels Lohmann cf9bf2d913 🚑 fix for #411 and #412 2017-01-01 15:28:01 +01:00
Daniel Cohen ff3221a375 #394 fixed memory leak in unit-allocator, found by clang's fsanitize 2016-12-30 15:21:25 +02:00
Niels Lohmann 328eb55dc4 🚧 started working on #397 2016-12-30 14:02:51 +01:00
Daniel Cohen 010ea126f3 going to try clang_sanitize with libstdc++ with g++-6 implementation
Conflicts:
	.travis.yml
	Makefile
2016-12-30 14:24:22 +02:00
Niels Lohmann d7029c37aa improved test coverage 2016-12-30 13:04:33 +01:00
Niels Lohmann f7575dee94 Merge branch 'develop' into feature/release_information 2016-12-30 12:29:01 +01:00
Niels Lohmann 42a8c64499 🔖 added version information 2016-12-30 12:28:52 +01:00
Niels Lohmann f0edab2363 🚑 fix for #408 2016-12-29 17:00:02 +01:00
Niels Lohmann 383a29a924 🚑 fix for #407 2016-12-29 16:14:15 +01:00
Niels Lohmann 871cebaf84 🚑 fix for #405 2016-12-29 15:39:16 +01:00
Niels Lohmann 8381cd6020 🚑 removed unsafe call to strerror #403 2016-12-28 14:19:08 +01:00
Niels Lohmann e4c2829aea 🔀 merge branch 'feature/fuzzer' into develop 2016-12-28 12:26:00 +01:00
Niels Lohmann 1dd99d04b6 Merge branch 'develop' into feature/fuzzer 2016-12-28 12:19:12 +01:00
Niels Lohmann 888f5b9f60 🚚 renamed test files to allow windows build 2016-12-28 12:18:48 +01:00
Niels Lohmann 55be721615 Merge branch 'develop' into feature/fuzzer 2016-12-28 12:11:51 +01:00
Niels Lohmann acb7e0558d 🚑 fixed bugs detected by AFL-Fuzz 2016-12-28 12:09:15 +01:00
Niels Lohmann e3b036348b 🚧 added targets for parallel AFL fuzzing 2016-12-25 16:36:43 +01:00
Niels Lohmann 1399abc583 🚧 added MessagePack fuzz target 2016-12-25 16:18:56 +01:00
Niels Lohmann e4cc62e653 🐛 fixed Makefile to work with proper CBOR files 2016-12-25 16:07:10 +01:00
Niels Lohmann 6de9d4035a 🐛 fixed AFL driver to also read binary data 2016-12-25 16:06:56 +01:00
Niels Lohmann dbdcb3fec8 🐛 fixed bug in CBOR/MessagePack deserialization 2016-12-25 16:06:36 +01:00
Niels Lohmann 6e129fbfb7 📝 some small documentation fixes 2016-12-25 14:39:08 +01:00
Niels Lohmann f87f4c06f9 🚧 cleanup 2016-12-22 12:10:52 +01:00
Niels Lohmann 33be4e7f1f 🚧 cleanup 2016-12-22 12:08:36 +01:00
Niels Lohmann a084e90f39 🔨 split AFL test in driver and test file 2016-12-22 11:09:26 +01:00
Niels Lohmann 048330b14b ⬆️ Catch v1.5.9 2016-12-22 09:37:15 +01:00
Niels Lohmann 22a6b956e8 📄 added license for Catch 2016-12-22 09:36:34 +01:00
Niels Lohmann ad241a2260 🔨 moved third-party code into separate folder 2016-12-22 09:35:53 +01:00
Niels Lohmann 6e8791912f 🚧 added fuzzer from OSS-Fuzz 2016-12-22 09:09:40 +01:00
Niels Lohmann 69ed19e483 added libFuzzer 2016-12-22 09:08:50 +01:00
Niels Lohmann 7107072f71 👷 clang for fedora 2016-12-21 10:33:36 +01:00
Niels Lohmann 2cf0f299ad 👷 using clang where GCC is too old 2016-12-21 10:13:59 +01:00
Niels Lohmann 937cca762f 👷 forgot to install make 2016-12-21 09:54:11 +01:00
Niels Lohmann 91e45a8dd0 👷 the cmake of trusty is too old 2016-12-21 09:47:31 +01:00
Niels Lohmann f78671de8e 👷 Fedora has no package "build-essential" 2016-12-21 09:33:16 +01:00
Niels Lohmann 2e5208d5cd 👷 there is no cmake in the osx image 2016-12-21 09:19:53 +01:00
Niels Lohmann c6fbd305b0 👷 trying more doozer workers 2016-12-21 09:17:17 +01:00
Niels Lohmann 38597ac628 👷 added more builders 2016-12-20 23:04:07 +01:00
Andreas Smas 57b32d9773 Add Doozer build badge 2016-12-20 21:38:01 +01:00
Niels Lohmann 73b28e8f92 👷 fixing build command 2016-12-20 19:16:52 +01:00
Niels Lohmann 1178a8152a 👷 using cmake with Doozer 2016-12-20 19:13:19 +01:00
Niels Lohmann 0fffbb8488 👷 trying Doozer 2016-12-20 19:06:15 +01:00
Niels Lohmann 9952a3c456 👷 trying to fix coverity task 2016-12-18 18:17:26 +01:00
Niels Lohmann 0e55af23fc 🔀 Merge branch 'release/2.0.9' into develop 2016-12-16 21:35:28 +01:00
Niels Lohmann 57afd293aa 🔖 updated documentation 2016-12-16 21:34:37 +01:00
Niels Lohmann a507b9b46a 🔖 updated documentation 2016-12-16 21:25:20 +01:00
Niels Lohmann 36dc786106 🔖 updated Changelog 2016-12-16 21:09:14 +01:00
Niels Lohmann 706be50596 📝 updated number of tests 2016-12-16 20:54:43 +01:00
Niels Lohmann 303e873ae8 🔖 bumped version to 2.0.9 2016-12-16 20:45:46 +01:00
Niels Lohmann f6f7fed99a 🚨 removed some warnings 2016-12-16 18:57:19 +01:00
Niels Lohmann f24e4f680e 🎨 cleanup after PR #395 2016-12-14 22:30:09 +01:00
Niels Lohmann fe00b368ae 🔀 merge pull request #395 from Bosswestfalen/develop
Replace class iterator and const_iterator by using a single template class to reduce code.
2016-12-14 21:56:43 +01:00
Niels Lohmann 2f94c30bad added a regression test for #380 / #390 2016-12-13 21:46:07 +01:00
Niels Lohmann 4e2fb1a533 Merge pull request #390 from qwename/integer-overflow
🔀 fix issue #380: Signed integer overflow check
2016-12-13 21:26:53 +01:00
Niels Lohmann dfafd2c259 👷 can't get clang sanitizer to work #394
See https://travis-ci.org/nlohmann/json/jobs/183684093 for a failing
build.
2016-12-13 21:23:59 +01:00
Bosswestfalen 92e28c3153 added missing changes in json.hpp.re2c 2016-12-13 20:30:56 +01:00
Niels Lohmann c3fac19692 👷 another try for sanitizers #394 2016-12-13 19:41:36 +01:00
Niels Lohmann 3f089cab2b 👷 moved instructed build to "before_script" #394 2016-12-13 18:24:16 +01:00
Niels Lohmann 9b5411db57 👷 clang 3.9.0 is not working #394 2016-12-13 17:55:41 +01:00
Niels Lohmann f5d4a9c4eb 👷 added Clang 3.9.0 and sanitizer build #394 2016-12-13 17:51:46 +01:00
Yixin Zhang 703d4baf8b Fixed conversion warnings
Use static_cast on digit.
2016-12-12 21:12:08 -05:00
Yixin Zhang bd6422f583 Ran make pretty 2016-12-12 21:12:08 -05:00
Yixin Zhang 1e981115c9 Fix issue #380: Signed integer overflow check
Instead of checking something like `x * y + z > max` where `x * y` can
overflow, check for `x > (max - z) / y` instead.
2016-12-12 21:12:08 -05:00
Niels Lohmann 79fa8b2f41 🚑 fix to address #389 2016-12-12 23:19:43 +01:00
Bosswestfalen dd3f4f9b92 Replaced class iterator and class const_iterator with aliases of template <typename U> iter_impl. iter_impl has operator const_iterator to create an const_iterator from an iterator. 2016-12-12 19:26:45 +01:00
Niels Lohmann 447e01427d 🚨 fixed some warnings 2016-12-12 18:21:17 +01:00
Niels Lohmann b8776e8613 🚑 fix for #393 2016-12-12 17:39:56 +01:00
Niels Lohmann f6c21a1f20 📝 added note to example files 2016-12-12 08:25:08 +01:00
Niels Lohmann 5402458ff5 🚑 fixed an AddressSanitizer warning 2016-12-12 08:13:26 +01:00
Niels Lohmann a25d570040 📝 added TOC to README #383 2016-12-11 19:42:36 +01:00
Niels Lohmann ea7b40687b 📝 updated FAQ of the contribution guidelines #382 2016-12-11 16:36:39 +01:00
Niels Lohmann b2991950a5 📝 added not wrt re2c version #390 2016-12-11 16:21:53 +01:00
Niels Lohmann e906933f39 🔀 Merge branch 'feature/messagepack' into develop 2016-12-11 16:11:59 +01:00
Niels Lohmann a59eb4868a 🔀 Merge branch 'develop' into feature/messagepack 2016-12-11 16:11:43 +01:00
Niels Lohmann a9d7d315a5 📝 cleanup after #391 2016-12-11 16:06:52 +01:00
Niels Lohmann 446019aefd 🔀 merge pull request #391 from jaredgrubb/jgrubb-clang-doc-warning
Clang: quiet a warning
2016-12-11 16:04:27 +01:00
Niels Lohmann 6fa4f96ba3 📝 fixed two documentation warnings 2016-12-11 16:03:23 +01:00
Niels Lohmann dc6fc3e079 📝 clean up and added documentation for #358 2016-12-11 13:36:08 +01:00
Niels Lohmann fdce38fa79 fixed a test case 2016-12-11 00:39:26 +01:00
Niels Lohmann e8c903294f more test cases for CBOR and msgpack 2016-12-11 00:05:29 +01:00
Niels Lohmann 41673e8fed 🐛 fixed CBOR code and added test cases 2016-12-10 23:12:57 +01:00
Jared Grubb 98d6e6e523 Clang: quiet a warning 2016-12-10 13:19:56 -08:00
Niels Lohmann 7e5d6af5c1 🔨 refactored msgpack code 2016-12-10 21:30:18 +01:00
Niels Lohmann f1b95d78f9 🔨 refactored CBOR code to a switch 2016-12-10 19:29:45 +01:00
Niels Lohmann d99c230f51 implemented indefinite-length CBOR types (#387) 2016-12-10 18:32:56 +01:00
Niels Lohmann 6b84c4155c 🔨 refactored get_from_vector function
Snippet from http://stackoverflow.com/a/41031865/266378
2016-12-08 09:37:23 +01:00
Niels Lohmann 81a4272444 more test cases for CBOR 2016-12-07 23:14:37 +01:00
Niels Lohmann 3a0f5398a2 more CBOR test cases 2016-12-07 22:50:10 +01:00
Niels Lohmann b7e0c12966 CBOR support for half-precision floats 2016-12-07 21:43:59 +01:00
Niels Lohmann 17c9b17a7e test cases from RFC 7049 #384 2016-12-07 21:25:22 +01:00
Niels Lohmann aab9bbbb93 🐛 fix for CBOR (small integers) 2016-12-07 21:24:42 +01:00
Niels Lohmann de289ea336 💚 another approach to the AppVeyor error 2016-12-07 19:15:05 +01:00
Niels Lohmann 81c43dca6a 💚 more AppVeyor fixes 2016-12-07 16:51:15 +01:00
Niels Lohmann 3f14a09e73 💚 another try to fix the AppVeyor build 2016-12-07 16:43:55 +01:00
Niels Lohmann 74571d531c 💚 still fixing the AppVeyor error 2016-12-07 16:34:02 +01:00
Niels Lohmann 2c7946f2bc 💚 hopefully fixed an error on AppVeyor 2016-12-07 16:21:22 +01:00
Niels Lohmann 8f6bfe5b32 🔨 refactored function to get numbers from byte vector 2016-12-07 14:47:06 +01:00
Niels Lohmann 474da6b28f :white_check_mark: more msgpack test cases 2016-12-07 13:47:08 +01:00
Niels Lohmann be973e52bb more msgpack test cases 2016-12-07 09:19:46 +01:00
Niels Lohmann a1693bfe48 Merge branch 'develop' into feature/messagepack 2016-12-07 08:39:57 +01:00
Niels Lohmann bc28942101 🔖 Merge branch 'release/2.0.8' into develop 2016-12-02 20:07:43 +01:00
Niels Lohmann 44c0f811b1 🔖 version 2.0.8 2016-12-02 20:05:53 +01:00
Niels Lohmann 6c24caf282 📝 updated ChangeLog 2016-12-02 19:04:36 +01:00
Niels Lohmann 4adb8a81bf 📝 version bump 2016-12-02 18:39:35 +01:00
Niels Lohmann 60b7299fe1 📝 updated README 2016-12-02 18:02:38 +01:00
Niels Lohmann 8f563a5f81 Merge branch 'feature/emplace' into develop 2016-12-01 21:22:23 +01:00
Niels Lohmann 5c811b91f1 Merge branch 'develop' into feature/emplace 2016-12-01 21:17:40 +01:00
Niels Lohmann ba3c5e1a25 more test cases 2016-11-29 09:49:05 +01:00
Niels Lohmann c46b4ea990 more test cases 2016-11-29 08:37:27 +01:00
Niels Lohmann e717492019 Merge branch 'feature/issue365' into develop 2016-11-29 07:46:14 +01:00
Niels Lohmann bd252b2a09 Merge branch 'develop' into feature/issue365 2016-11-28 23:24:52 +01:00
Niels Lohmann 50f647c866 Merge branch 'develop' into feature/messagepack 2016-11-28 23:24:35 +01:00
Niels Lohmann 7b6bd585c1 Merge branch 'develop' into feature/emplace 2016-11-28 23:23:56 +01:00
Niels Lohmann d563c21afe 📝 update documentation of Travis builders 2016-11-28 23:23:45 +01:00
Niels Lohmann ee0f23fdc6 🚧 bug fixes and more tests 2016-11-28 23:20:03 +01:00
Niels Lohmann 286025497f 👷 removed retired images (https://blog.travis-ci.com/2016-11-17-retiring-some-osx-images/) 2016-11-28 22:16:33 +01:00
Niels Lohmann aeb4f87a27 added return value for emplace (#349) 2016-11-28 18:33:46 +01:00
Niels Lohmann 6ecff31b7f Merge branch 'develop' into feature/emplace 2016-11-28 18:00:10 +01:00
Niels Lohmann bc238124ee 🚧 further simplifications 2016-11-27 21:42:21 +01:00
Niels Lohmann 4c232fe12b 👷 added precondition for individual tests 2016-11-27 19:11:58 +01:00
Niels Lohmann a820d688eb 🔨 refactored number-to-vector calls 2016-11-27 19:11:32 +01:00
Niels Lohmann 56843eb7ba Merge branch 'feature/individual_tests' into feature/messagepack 2016-11-27 18:28:23 +01:00
Niels Lohmann 93589e630c CBOR roundtrip tests 2016-11-27 17:47:56 +01:00
Niels Lohmann 2477b09cb9 🐛 Clang 3.9.0 seems to not work right now 2016-11-27 17:29:19 +01:00
Niels Lohmann f860f323be 🚧 falling back to single unit test for coveralls 2016-11-27 17:09:05 +01:00
Niels Lohmann 71c1232e32 🐛 fixed YAML 2016-11-27 16:46:33 +01:00
Niels Lohmann 36c79113fb 🚧 fixing coveralls and valgrind targets 2016-11-27 16:45:24 +01:00
Niels Lohmann e1f98fbfc0 🚧 splitting tests into several binaries 2016-11-27 16:19:26 +01:00
Niels Lohmann a73f43a7a2 🚧 CBOR support (#358) 2016-11-27 00:10:04 +01:00
Niels Lohmann eef408e5fb tests for CBOR 2016-11-27 00:09:24 +01:00
Niels Lohmann 87e088990b Merge branch 'develop' into feature/messagepack 2016-11-26 18:17:18 +01:00
Niels Lohmann a8522f391a Merge branch 'develop' into feature/issue365 2016-11-26 12:45:50 +01:00
Niels Lohmann 2773038cf9 added improvements (#365) 2016-11-26 12:43:23 +01:00
Niels Lohmann a791af30b4 Merge branch 'feature/filenotfound' into develop 2016-11-25 17:39:38 +01:00
Niels Lohmann 1ed510c232 Merge branch 'develop' into feature/filenotfound 2016-11-25 17:39:24 +01:00
Niels Lohmann f194db9aa6 added assertion for warning from #368 2016-11-24 22:07:35 +01:00
Niels Lohmann c39c36e6ad 💄 fixed indentation 2016-11-24 22:05:29 +01:00
Niels Lohmann 472d0045ba 📝 updating README after fixing #299 2016-11-24 21:56:21 +01:00
Niels Lohmann 1407bbf94c 💄 fixed indentation 2016-11-24 21:54:05 +01:00
Niels Lohmann 8014637ad1 added a test for EOF error (#367) 2016-11-24 21:53:41 +01:00
Niels Lohmann dfc49e7afe 🐛 fixed a bug if parser was called with a stream at EOF (#367) 2016-11-24 21:45:10 +01:00
Niels Lohmann 4bd3b1b0ef Merge branch 'develop' into feature/issue365 2016-11-24 18:25:00 +01:00
Niels Lohmann e3450cac72 📈 removing more variance of the benchmarks 2016-11-24 18:24:26 +01:00
Niels Lohmann c3a610d32a 🔧 ignoring Clion files 2016-11-24 17:45:01 +01:00
Niels Lohmann 25548f85c9 👷 trying Coverity with Clang 3.6 (#299) 2016-11-24 17:25:05 +01:00
Niels Lohmann 4bb41d065b 🐛 parsing erroneous files yields an exception (#366) 2016-11-23 16:57:01 +01:00
Niels 5f4becb0f5 Merge branch 'develop' into feature/issue365 2016-11-23 08:48:54 +01:00
Niels ed611119d9 📈 reducing benchmark variance (#365) 2016-11-23 08:47:40 +01:00
Niels 6cc2d58d69 🐛 hopefully fixing the crashes on Linux (#365) 2016-11-22 20:13:47 +01:00
Niels f620d74919 added performance fixes (#365) 2016-11-22 07:26:11 +01:00
Niels 869f4c68d4 📝 updated thanks section 2016-11-22 07:25:40 +01:00
Niels c34b41acd6 🐛 fixes crash in dump from static object (#359)
Merge branch 'feature/issue359' into develop
2016-11-22 06:57:58 +01:00
Niels abce5c25bb 📝 cleaned comments and updated README 2016-11-21 23:38:17 +01:00
Niels 43dbe02d5b 🐛 fixing #359 2016-11-21 21:53:10 +01:00
Niels edc81f3bc1 💚 restored test call 2016-11-16 22:49:25 +01:00
Niels d362a07239 💚 moved sample.json to standard test suite to run it with Valgrind 2016-11-16 22:49:16 +01:00
Niels a9744f3937 💚 is sample.json killing AppVeyor? 2016-11-16 22:08:21 +01:00
Niels 0c9ab9427f 💚 added verbose message to check AppVeyor build 2016-11-16 22:02:38 +01:00
Niels 05e916717b Merge branch 'develop' into feature/messagepack 2016-11-16 19:16:36 +01:00
Niels 693bfe439b Merge branch 'develop' into feature/emplace 2016-11-16 19:16:16 +01:00
Niels 0d72767b3e ⬆️ updated to Catch v1.5.8 2016-11-16 19:15:54 +01:00
Niels 56667af823 🎨 stating the name of the library in the license 2016-11-16 19:08:25 +01:00
Niels 0a908ce8e2 Merge branch 'develop' into feature/messagepack 2016-11-16 09:04:37 +01:00
Niels b0f896558f Merge branch 'develop' into feature/emplace 2016-11-16 09:04:25 +01:00
Niels 425b9834a8 🐛 removed the wrong compiler 2016-11-16 08:25:08 +01:00
Niels 56671a88c6 🍎 removed Xcode 8.0 due to repeated problems 2016-11-16 08:01:48 +01:00
Niels 5316f0fff2 🍎 added Xcode 8.1 build for travis 2016-11-16 06:42:26 +01:00
Niels 1be73b903e proposal for emplace/emplace_back (#349) 2016-11-11 19:29:14 +01:00
Niels d1e73ce954 hid an expensive test case 2016-11-11 17:31:37 +01:00
Niels 543745a10e starting to integrate MessagePack (#358) 2016-11-11 17:11:13 +01:00
Niels 9ca00e4880 readded missing header 2016-11-03 07:27:32 +01:00
Niels e385417047 documented and cleaned up headers (#314) 2016-11-02 21:27:19 +01:00
Niels 6d2b5e3771 Merge branch 'release/2.0.7' into develop 2016-11-02 20:52:42 +01:00
Niels 700977d73e version bump 2016-11-02 20:52:15 +01:00
Niels 79015b9d0a Merge branch 'feature/jsontestsuite' into develop 2016-11-02 17:03:17 +01:00
Niels 3716a2fbe8 Merge branch 'develop' into feature/jsontestsuite 2016-11-02 17:03:12 +01:00
Niels 737d43724f Merge branch 'feature/issue329' into develop 2016-11-02 16:59:23 +01:00
Niels 59c8343851 cleanup 2016-11-02 15:44:46 +01:00
Niels 94c16b2c31 fixed coverage 2016-11-01 17:01:04 +01:00
Niels 8f70525374 more test coverage 2016-10-30 17:46:00 +01:00
Niels 7adccde714 improved coverage and updated README 2016-10-30 17:10:11 +01:00
Niels 8d1e65f297 evaluated i-tests (#344) 2016-10-30 16:07:17 +01:00
Niels 7b4e6cf705 added implementation-specific tests (#344) 2016-10-30 12:08:29 +01:00
Niels a8136c578a fixed BOM handling #344 2016-10-29 21:08:30 +02:00
Niels b820bb3b1f fixed a lot of unicode errors (#344)
BOMs currently yield an error.
2016-10-29 19:35:17 +02:00
Niels b03bbe724d added n test cases (#344) 2016-10-29 14:02:33 +02:00
Niels 7da182472d Merge branch 'develop' into feature/jsontestsuite 2016-10-29 13:37:17 +02:00
Niels 42ea4fb751 fixed a bug for short input files (#344)
For input files with less than 5 bytes, the parser had a bug so that
refilling the input buffer led to erasing it.
2016-10-29 13:32:36 +02:00
Niels 2fdba9de19 added "y" cases 2016-10-26 23:45:11 +02:00
Niels a2808322c6 add test files from https://github.com/nst/JSONTestSuite 2016-10-26 18:57:56 +02:00
Niels Lohmann a29fcae409 fixed Cmake link 2016-10-26 09:20:40 +02:00
Niels 3ebe28970a small fixes 2016-10-23 17:25:07 +02:00
Niels 79d9fdc016 user-defined string literals exploit string length (#340) 2016-10-22 18:57:58 +02:00
Niels e310850353 cleanup after #336 2016-10-16 23:46:24 +02:00
Niels Lohmann 8057782bb8 Merge pull request #336 from seeekr/patch-1
fix minor grammar/style issue in README.md
2016-10-16 23:40:17 +02:00
Denis Andrejew cb2d41e3a0 fix minor grammar/style issue in README.md 2016-10-16 02:46:43 +02:00
Niels 542a48a16a Merge branch 'release/2.0.6' into develop 2016-10-15 16:48:08 +02:00
Niels 606098f45d release 2.0.6 2016-10-15 16:47:45 +02:00
Niels d91067220f added missing overflow check for #329 2016-10-13 21:00:48 +02:00
Niels 67b9f1936d cleanup after closing #324 2016-10-12 22:05:45 +02:00
Niels Lohmann bb9d87ad55 Merge pull request #324 from vpetrigo/has_mapped_improve
make has_mapped_type struct friendly
2016-10-12 21:59:56 +02:00
Niels e7a60d8961 Merge branch 'feature/issue323' into develop 2016-10-12 21:21:59 +02:00
Niels 470197bd0b improve test coverage 2016-10-10 21:58:31 +02:00
Niels d3e7f9da67 code cleanup for #323 2016-10-10 20:38:50 +02:00
Niels 97280bbcfc added missing header 2016-10-09 16:32:01 +02:00
Vladimir Petrigo e9fde3e116 make has_mapped_type struct friendly 2016-10-08 16:50:23 +03:00
Niels 54bf5f20e9 adjusted README 2016-10-08 14:33:10 +02:00
Niels 2fa8ea0f74 started fixing #323 2016-10-08 14:27:28 +02:00
Niels a0ef5a194c addressed #319, #321, and #318 2016-10-06 23:27:43 +02:00
Niels Lohmann 04b11d78ff Merge pull request #318 from ChristophJud/include_dir_relocation
Include dir relocation
2016-10-06 22:35:36 +02:00
Niels Lohmann 8173c370f6 Merge pull request #321 from vasild/develop
Fix usage examples' comments for std::multiset
2016-10-06 22:33:58 +02:00
Niels b6550b35c3 fix after #313 2016-10-04 18:20:36 +02:00
Vasil Dimov b5128b1610 Fix usage examples' comments for std::multiset 2016-10-04 18:53:44 +03:00
Niels Lohmann 963efb1f09 Merge pull request #313 from 5tefan/develop
trivial documentation fix
2016-10-02 11:29:49 +02:00
Niels d6005e59a5 added fuzzing results 2016-10-02 11:23:47 +02:00
Christoph Jud e1b6a23049 relocation of install-include directory for other packages 2016-09-26 12:15:03 +02:00
Stefan Codrescu be61091401 trivial documentation fix 2016-09-16 18:15:36 -06:00
Niels e4366688f7 v2.0.5 2016-09-14 23:42:12 +02:00
Niels 5dfd2c9bdf Merge branch 'release/2.0.5' into develop 2016-09-14 23:07:14 +02:00
Niels 5879eb0be3 Merge branch 'release/2.0.5' 2016-09-14 23:06:53 +02:00
Niels 3d104f1d43 version bump 2016-09-14 23:06:39 +02:00
Niels 6bbcdc1ec5 fixes #310 2016-09-14 22:48:12 +02:00
Niels 7b6cba23f3 results for #307 2016-09-12 21:23:12 +02:00
Niels 24c588cd25 Merge branch 'release/2.0.4' into develop 2016-09-11 23:37:30 +02:00
Niels f209be1142 Merge branch 'release/2.0.4' 2016-09-11 23:37:11 +02:00
Niels 768d66560e version bump 2016-09-11 23:36:59 +02:00
Niels 15925469c6 Travis updated their Xcode 2016-09-11 22:50:40 +02:00
Niels f922426ec3 fixed #304 2016-09-11 22:40:51 +02:00
Niels 2daab5a4c2 fixed #306 2016-09-11 22:30:08 +02:00
Niels 8ea0ee502d clang 3.9.0 is not working yet 2016-09-03 13:08:17 +02:00
Niels fa0299f03a moved cmake into clang 2016-09-03 12:30:10 +02:00
Niels 36745ed296 install from tarball 2016-09-03 10:34:52 +02:00
Niels f0455b401d forgot sh call 2016-09-03 09:44:10 +02:00
Niels e0d809312b the cmake in apt is too old 2016-09-03 09:17:30 +02:00
Niels bfd6678800 clang 3.9.0 needs a newer cmake 2016-09-03 08:47:07 +02:00
Niels 9639f0dfb3 Clang 3.9.0 has been released 2016-09-03 00:37:45 +02:00
Niels 625370a1ad Merge branch 'develop' 2016-09-02 16:05:38 +02:00
Niels 357baeff5a release 2.0.3 2016-09-01 08:07:52 +02:00
Niels 42be2edd4c fixed test coverage 2016-09-01 00:29:42 +02:00
Niels c8d01fa7b9 Merge branch 'release/2.0.3' into develop 2016-08-31 21:27:50 +02:00
Niels 2c82f25272 Merge branch 'release/2.0.3' 2016-08-31 21:27:32 +02:00
Niels df9fd6237e release 2.0.3 2016-08-31 21:27:23 +02:00
Niels 776880bc49 Merge branch 'feature/iterator_range_parsing' into develop 2016-08-31 20:23:24 +02:00
Niels 740b66f225 cleanup 2016-08-31 20:23:21 +02:00
Niels 58cbf4b3ef added another test case 2016-08-31 18:23:46 +02:00
Niels ae7aaed4ac Merge branch 'develop' into feature/iterator_range_parsing 2016-08-31 18:07:18 +02:00
Niels 442058f8ed interface cleanup 2016-08-31 17:07:35 +02:00
Niels afba1d3fcb forgot to run re2c 2016-08-30 23:51:14 +02:00
Niels 941714c99c template changes did not work with MSVC 2016-08-30 23:49:06 +02:00
Niels a485aa8d27 cleanup and improvement of branch coverage 2016-08-30 23:44:15 +02:00
Niels 6e6e1c9b1f implemented idea from #290 2016-08-30 18:26:07 +02:00
Niels f76f9efe58 Merge branch 'develop' into feature/iterator_range_parsing 2016-08-30 18:20:13 +02:00
Niels Lohmann 463ffb21bc Merge pull request #300 from t-b/fix_warning_in_test_case
unit-constructor1.cpp: Fix floating point truncation warning
2016-08-29 22:52:18 +02:00
Niels 29c5f32d42 fixed performance degradation (#272) 2016-08-29 22:36:33 +02:00
Thomas Braun e0ff1a837c unit-constructor1.cpp: Fix floating point truncation warning 2016-08-25 00:24:33 +02:00
Niels Lohmann 87dea32e81 using AppVeyor badge for develop branch 2016-08-24 21:31:11 +02:00
Niels Lohmann bd3bd37e96 removed coverity badge (build is broken, see #299) 2016-08-24 21:29:28 +02:00
Niels 04c6c886eb another experiment 2016-08-24 21:02:33 +02:00
Niels Lohmann 8b833c452a experiment: changed order of parse functions 2016-08-24 07:12:56 +02:00
Niels 1d66ab9f7a fixed lexer issue which required null byte at the end of contiguous storage containers #290 2016-08-23 22:38:05 +02:00
Niels a79d634ccb integrated proposals for #290 2016-08-22 21:40:07 +02:00
Niels 6d1254baba Merge branch 'develop' into feature/iterator_range_parsing 2016-08-22 20:54:55 +02:00
Niels b688119aa4 reverted .travis file 2016-08-22 20:54:32 +02:00
Niels 29a4ef6c5c no execution for special cases 2016-08-22 20:50:12 +02:00
Niels 71af209ea9 fix for YAML file 2016-08-22 20:44:36 +02:00
Niels 79fd4dfbd8 do not build for special cases 2016-08-22 20:40:25 +02:00
Niels cda84ba323 Merge branch 'develop' into feature/iterator_range_parsing 2016-08-21 23:15:27 +02:00
Niels 034244a291 Merge branch 'feature/coverage' into develop 2016-08-21 22:48:02 +02:00
Niels 1e896eb91e improved code coverage 2016-08-21 22:38:56 +02:00
Niels 94331a355d removed LCOV_EXCL_LINE 2016-08-21 21:50:13 +02:00
Niels aa7f5ad8b1 minor changes 2016-08-21 21:48:15 +02:00
Niels 585a39a235 improved branch coverage 2016-08-21 14:39:54 +02:00
Niels b4571360df more on #290 2016-08-21 12:35:40 +02:00
Niels eef8059003 allowing parsing from contiguous containers 2016-08-20 20:29:33 +02:00
Niels 6f3554f040 Merge branch 'develop' into feature/iterator_range_parsing 2016-08-20 18:51:11 +02:00
Niels 0cf7ebaa57 mentioning the CII 2016-08-18 18:43:27 +02:00
Niels d2564c6100 added cppcheck target for travis 2016-08-18 18:29:19 +02:00
Niels 039cedaf8e changes to address #295 2016-08-17 23:14:28 +02:00
Niels 628a5eae50 reset build file 2016-08-17 22:33:26 +02:00
Niels f40f81c87e forgot a semicolon 2016-08-17 21:44:53 +02:00
Niels c0922c7aac /Wall 2016-08-17 21:43:28 +02:00
Niels 35f22e8596 checking MSVC compiler flags 2016-08-17 21:38:19 +02:00
Niels a78eaa27b5 fixed unit tests 2016-08-17 21:31:59 +02:00
Niels 5e67f7af01 added a first version of a parser for #290 2016-08-15 22:44:14 +02:00
Niels f791c5fd2e Merge branch 'develop' into feature/iterator_range_parsing 2016-08-15 21:46:02 +02:00
Niels ca80a71c28 added notes from the CII Best Practices badge 2016-08-15 21:45:49 +02:00
Niels dfc2c1abe5 added assertion for contiguous memory 2016-08-14 23:38:20 +02:00
Niels 92ee1d56eb cleanup 2016-08-14 21:59:41 +02:00
Niels 4871e39415 spell fix 2016-08-14 17:52:21 +02:00
Niels 7b42c973bd fix for MSVC 2016-08-14 17:34:58 +02:00
Niels c9e5d56c9c fix for MSVC 2016-08-14 17:30:53 +02:00
Niels 01386b3977 cleanup 2016-08-14 17:23:15 +02:00
Niels b76f5506d7 added a parser for continguous containers 2016-08-14 14:18:25 +02:00
Niels 03de590372 improved documentation for #289 2016-08-11 20:52:48 +02:00
Niels 37fdcd893d Merge branch 'feature/travis' into develop 2016-08-10 22:50:11 +02:00
Niels 46174879ef clean up 2016-08-10 22:41:09 +02:00
Niels 5db41313ba valgrind + full unit tests takes too long 2016-08-10 21:33:03 +02:00
Niels 1c4ca6d7b1 rubygems -> ruby 2016-08-10 21:00:36 +02:00
Niels d02e67d4a9 coveralls with lcov 2016-08-10 20:56:26 +02:00
Niels ce30526ee8 fixed Valgrind call 2016-08-10 19:35:27 +02:00
Niels efe1d52629 added coverity, coveralls, and valgrind 2016-08-10 18:54:19 +02:00
Niels a2e923de32 removed clang 3.5.x 2016-08-10 18:38:31 +02:00
Niels 4d90331718 a test 2016-08-10 17:42:33 +02:00
Niels 997bc5d1ab more clang versions 2016-08-10 16:56:05 +02:00
Niels 31963723d3 no directory change 2016-08-10 16:35:57 +02:00
Niels 407e8dbb8e fixed YAML error 2016-08-10 16:25:35 +02:00
Niels b1c1fe9d39 added Clang 3.8 2016-08-10 16:22:53 +02:00
Niels b76861dde5 commit to re-fix issue #195 2016-08-09 23:05:42 +02:00
Niels 6150ffb9dc more compilers 2016-08-09 22:49:08 +02:00
Niels be05dbe618 moved sources 2016-08-09 22:33:31 +02:00
Niels 4b37082e36 more GCC versions 2016-08-09 22:29:01 +02:00
Niels 117fd59abd first try 2016-08-09 22:18:13 +02:00
Niels ff612e0e39 reverted last commit 2016-08-09 18:33:06 +02:00
Niels 0b34ddd47a another try for coveralls 2016-08-09 18:19:54 +02:00
Niels fa4fd334b2 accidentially deleted env 2016-08-05 08:56:58 +02:00
Niels d3c6ed08d6 set build-root 2016-08-05 08:40:42 +02:00
Niels 00046f6ff1 fix for coveralls 2016-08-05 08:18:19 +02:00
Niels 38f562af2a reorganization into smaller test units 2016-08-04 22:51:08 +02:00
Niels 2d3374c8b2 removed codecov 2016-08-04 22:10:30 +02:00
Niels bd75ef9f27 added check-fast flag 2016-08-04 22:05:16 +02:00
Niels ff592c6d50 adjusted warning flags 2016-08-04 22:05:05 +02:00
Niels 91b6e223d9 adjusted capacity test cases 2016-08-04 22:04:55 +02:00
Niels d80329034e split test suite in one file per test case 2016-08-04 21:55:47 +02:00
Niels 3944ecd470 chose correct flags 2016-08-04 07:40:04 +02:00
Niels be5cf0e3ba forgot to pass CPPFLAGS 2016-08-04 07:33:44 +02:00
Niels 5541e6f6f9 split unit tests 2016-08-04 07:24:46 +02:00
Niels 263e6af48d switch off assertions for benchmarks 2016-07-31 23:03:14 +02:00
Niels 4444ef9396 version bump 2016-07-31 14:39:15 +02:00
Niels 9e67dc46fa Merge branch 'release/v2.0.2' into develop 2016-07-31 13:37:49 +02:00
Niels 3586767c05 Merge branch 'release/v2.0.2' 2016-07-31 13:37:26 +02:00
Niels a05df038cd prepared release 2016-07-31 13:37:04 +02:00
Niels 9e51c9041e replaced individual assertions by a class invariant function 2016-07-30 18:02:41 +02:00
Niels 891918a30f cleanup and documentation 2016-07-30 16:12:10 +02:00
Niels 5405ae8601 added default value 2016-07-30 10:50:53 +02:00
Niels b145e0c404 more cleanup 2016-07-29 23:47:16 +02:00
Niels b2b68a0fa1 header + cleanup 2016-07-29 22:24:47 +02:00
Niels 161c74a92e some cleanup 2016-07-28 21:19:56 +02:00
Niels 6297631e22 reverted breaking changes 2016-07-27 21:40:15 +02:00
Niels a7f8c47f68 cleaned up code
- removed unnecessary assertions
- simplified simple if/return patterns
2016-07-27 21:29:55 +02:00
Niels bdaade91f5 fixed some errors in the README gif 2016-07-27 17:07:00 +02:00
Niels 5e88c6f254 more on travis 2016-07-25 23:41:16 +02:00
Niels cc8102f0c4 used the wrong variable 2016-07-25 22:19:49 +02:00
Niels fd7c7be851 fixed bash errors 2016-07-25 19:38:51 +02:00
Niels 148fed1e63 minor change 2016-07-25 18:06:59 +02:00
Niels 02fc3cddee test homebrew on OSX 2016-07-25 16:48:26 +02:00
Niels a01ec918ac minor changes 2016-07-25 16:21:15 +02:00
Niels d08e013dd0 improved documentation 2016-07-25 16:06:13 +02:00
Niels 369671f028 added more Unicode tests 2016-07-25 16:05:58 +02:00
Niels dcea3a283c Merge branch 'feature/issue283' into develop (fixes #278) 2016-07-24 11:16:47 +02:00
Niels 84673b7de3 added test case from issue #283 2016-07-24 11:08:39 +02:00
Niels e2aa2d2189 improved test coverage 2016-07-24 11:01:47 +02:00
Niels 75dbbc55cf started to implement #283 2016-07-23 09:59:09 +02:00
Niels ddfe86cc49 fixed a bug that was found in the discussion of #274 2016-07-22 21:40:58 +02:00
Niels 51a3829680 reverted change to constexpr get_ref (does not work with GCC and MSVC) 2016-07-22 15:53:38 +02:00
Niels 4e7501e59a minor changes
- fixed a bug that did not discard strings with control characters
between 0x10 and 0x1f
- added termination proofs for two important loops
- made get_ref() constexpr
2016-07-22 15:34:45 +02:00
Niels 4c98c971b8 added benchmarks for numbers 2016-07-20 23:06:45 +02:00
Niels 1286d35767 make sure precision is reset on output streams during serialization 2016-07-20 20:07:45 +02:00
Niels cb145cfe71 updated Changelog 2016-07-19 22:43:56 +02:00
Niels 0f834056bb removed unused header 2016-07-19 22:17:43 +02:00
Niels 2478be807c avoid recursion in the scanner 2016-07-19 22:10:27 +02:00
Niels b64367e2f7 fix for #279 2016-07-18 16:22:10 +02:00
Niels 7f4dd5d608 added header for int64_t and uint64_t (fixes #282) 2016-07-15 19:44:19 +02:00
Niels 8116413106 Merge pull request #279 from murinicanor/patch-1
let the makefile choose the correct sed
2016-07-10 00:32:32 +02:00
Muri Nicanor 01f9ee5fd7 let the makefile choose the correct sed 2016-07-09 20:02:41 +02:00
Niels 98d48ef0c2 fixed indentation 2016-07-04 00:04:22 +02:00
Niels 71d20db4fc Merge branch 'feature/improved_documentation' into develop
- improved documentation
2016-07-01 18:02:37 +02:00
Niels c6d45c30d5 Merge branch 'feature/parser_performance' into develop
- improved parser performance by avoiding a copy of the result value
2016-07-01 17:44:27 +02:00
Niels 8f9f561742 Merge branch 'feature/detect_unsupported_compilers' into develop
- added error macros to exclude unsupported compilers
2016-07-01 17:42:36 +02:00
Niels 513fac589b Merge branch 'feature/algorithm_loops' into develop
- replaces some raw loops by std algorithms
- used std::advance where possible
2016-07-01 17:39:25 +02:00
Niels bd7cd330cd fixed type_name() signature 2016-07-01 17:26:09 +02:00
Niels 28644bada0 removed std::out output from test cases 2016-07-01 17:25:56 +02:00
Niels 05ddfaf5cf Merge branch 'develop' into feature/improved_documentation 2016-07-01 17:01:02 +02:00
Niels 6e1347e68c fixes #270 2016-07-01 16:58:50 +02:00
Niels 26cab42c38 some minor improvements 2016-07-01 16:52:05 +02:00
Niels 814fb31d64 Merge pull request #275 from dtoma/develop
Update hexify to use array lookup instead of ternary (#270)
2016-07-01 16:51:35 +02:00
Niels a5262c18e2 replaced a copy by a move to increase performance by 16-25% 2016-06-30 12:43:06 +02:00
dtoma 5c129c8981 Update hexify to use array lookup instead of ternary (#270) 2016-06-29 19:28:56 +08:00
Niels 52cbda8048 using std::advance where possible 2016-06-29 12:47:29 +02:00
Niels a0609b2da3 fixed coverage bug 2016-06-29 09:53:48 +02:00
Niels 924f78119b math... 2016-06-29 09:34:14 +02:00
Niels 7cb8ee42d5 wrong GCC version 2016-06-29 09:22:28 +02:00
Niels d456dec320 overlapping defines 2016-06-29 09:16:18 +02:00
Niels fc7f4b8fba replace some raw loops with algorithms 2016-06-28 22:49:05 +02:00
Niels dc479b3f9d check for unsupported compilers 2016-06-28 22:09:22 +02:00
Niels 7ffa07e3a3 update of ChangeLog 2016-06-28 21:46:53 +02:00
Niels d2475f9010 bumped version number 2016-06-28 21:44:03 +02:00
Niels 8b39570009 Merge branch 'develop' 2016-06-28 21:40:23 +02:00
Niels 3d4c79922e Merge branch 'release/2.0.1' into develop 2016-06-28 21:38:59 +02:00
Niels e29d6b5f41 Merge branch 'release/2.0.1' 2016-06-28 21:33:43 +02:00
Niels 026fe8041d adjusted Changelog 2016-06-28 21:33:34 +02:00
Niels a73bda8147 fixed performance regression #272 2016-06-28 21:24:18 +02:00
Niels 6a108bb84b Merge branch 'feature/issue272' into develop 2016-06-28 21:19:36 +02:00
Niels 7214243d89 reset locale (for #272) 2016-06-28 19:18:23 +02:00
Niels 420659f187 addressing #272 2016-06-28 10:42:17 +02:00
Niels 360f0f3791 updated README and ChangeLog 2016-06-24 17:39:03 +02:00
Niels c74b9ff4f7 another fix for the MSVC version 2016-06-24 17:15:54 +02:00
Niels a61231ad29 Merge pull request #271 from thelostt/patch-1
fixed a tiny typo
2016-06-24 11:28:01 +02:00
Mário Feroldi 6aad67af23 fixed a tiny typo 2016-06-24 05:47:00 -03:00
Niels 0767290c26 off-by-one error in the documentation 2016-06-24 08:06:41 +02:00
Niels ca2bbdb15b clarified MSV version 2016-06-24 07:39:08 +02:00
Niels 25ccf7f908 Merge branch 'release/2.0.0' 2016-06-24 00:46:36 +02:00
Niels 1c719561b0 update of documentation links 2016-06-24 00:14:27 +02:00
Niels b3cf45c8f5 updated release information 2016-06-23 23:34:41 +02:00
Niels 6542ae5766 fixed re2c warnings 2016-06-23 22:49:48 +02:00
Niels 39a9cfcc12 updated README 2016-06-23 18:08:20 +02:00
Niels f86fe57c18 Merge branch 'feature/undo-number-roundtrip' into develop 2016-06-23 18:00:06 +02:00
Niels 04a80a8f60 Merge branch 'develop' into feature/undo-number-roundtrip 2016-06-23 05:57:41 +02:00
Niels 3497fab3b5 cleanup 2016-06-23 05:55:48 +02:00
Niels d14366c33e Merge branch 'feature/issue269' into develop 2016-06-23 00:05:01 +02:00
Niels 7cff6c8771 Merge branch 'develop' into feature/issue269
# Conflicts:
#	README.md
2016-06-23 00:04:55 +02:00
Niels 6f76c9237b overworked ChangeLog and README 2016-06-22 22:20:55 +02:00
Niels ecf84dddb1 test case for #269 2016-06-22 20:40:15 +02:00
Niels 59e67e768f fix for previous commit 2016-06-22 20:09:06 +02:00
Niels 3f97a5d5ad a conceptual quick fix for #269 2016-06-22 20:05:44 +02:00
Niels 15a314abea updated README 2016-06-19 22:38:54 +02:00
Niels 0865ec87d4 re-added GCC6 2016-06-19 22:20:02 +02:00
Niels 3fe654e827 fix for coverity 2016-06-19 22:12:56 +02:00
Niels 20e4b20528 fix SSL issue with coverity 2016-06-19 21:57:32 +02:00
Niels 90b46868b5 Merge branch 'develop' into feature/undo-number-roundtrip 2016-06-19 18:27:07 +02:00
Niels 8c48ef1f73 updated to Catch v1.5.6 2016-06-19 18:25:43 +02:00
Niels b47fdf88ee Merge branch 'develop' into feature/undo-number-roundtrip 2016-06-19 17:59:53 +02:00
Niels 4ff27b207e fixed two typos 2016-06-19 17:56:58 +02:00
Niels ad7a419a03 removed roundtripping of floats (#230) 2016-06-19 17:13:13 +02:00
Niels 4e31a0e852 minor doc changes 2016-06-19 16:17:53 +02:00
Niels 039565b9f5 trying codecov 2016-06-18 14:33:29 +02:00
Niels bb8c7b1f45 mentioning Homebrew's --HEAD parameter 2016-06-15 21:28:27 +02:00
Niels 1eced269e3 update after PR #266 2016-06-14 15:27:21 +02:00
Niels 9eb86e1e12 Merge pull request #266 from 06needhamt/Issue
Fix Issue #265
2016-06-14 15:24:49 +02:00
Tom Needham fb90388af5 Fix Issue #265 2016-06-14 09:59:50 +01:00
Niels 39213bf34e Merge branch 'feature/issue260' into develop 2016-06-14 08:28:36 +02:00
Niels 44b210aa77 Merge branch 'develop' into feature/issue260 2016-06-14 08:23:09 +02:00
Niels c744d59f2d adjusted README file to reality in Travis 2016-06-14 08:14:25 +02:00
Niels 947db6ffe3 added Xcode 8 beta 2016-06-14 08:02:29 +02:00
Niels 494cc15650 Merge branch 'develop' into feature/issue260 2016-06-07 12:13:03 +02:00
Niels 48f69f40e7 enough for today... 2016-06-07 12:04:57 +02:00
Niels 97648314a4 setting explicit path to compiler 2016-06-07 11:52:12 +02:00
Niels 439563eb04 export 2016-06-07 11:42:34 +02:00
Niels 19be324f87 ? 2016-06-07 11:38:56 +02:00
Niels 3f23e70598 another try 2016-06-07 11:36:03 +02:00
Niels 62f39c41ec another try 2016-06-07 11:29:37 +02:00
Niels c425dc9e04 trying to install clang 2016-06-07 11:25:00 +02:00
Niels a4058b88ec another test 2016-06-07 11:14:02 +02:00
Niels ff8f196ca3 a test 2016-06-07 11:13:15 +02:00
Niels 31b24dd5c1 adding more Clang versions 2016-06-07 11:02:45 +02:00
Niels cc5cad5b0b another try 2016-06-07 10:53:18 +02:00
Niels 1f04c0349a readded -lc++ 2016-06-07 10:03:18 +02:00
Niels a97c998791 removed -lc++ 2016-06-07 09:50:43 +02:00
Niels 6d19bd1108 Revert "another try"
This reverts commit f63317dce3.
2016-06-07 09:49:11 +02:00
Niels f63317dce3 another try 2016-06-07 09:34:46 +02:00
Niels 32cc6fefcc another try 2016-06-07 09:12:53 +02:00
Niels fbbdcb19bc another try 2016-06-07 09:01:49 +02:00
Niels dd10c89a3e another try 2016-06-07 08:53:36 +02:00
Niels dd542aae7d another try 2016-06-07 08:40:25 +02:00
Niels 761880f5b7 CPATH does not work... 2016-06-07 08:32:56 +02:00
Niels 1826d12a22 added CPATH 2016-06-07 08:28:50 +02:00
Niels dfc39b95ab clang does not work with travis right now 2016-06-07 07:54:00 +02:00
Niels 32f6682177 another try 2016-06-07 07:25:11 +02:00
Niels f4ae8f8e2e another try 2016-06-07 07:21:17 +02:00
Niels e772f06f0d another try 2016-06-07 07:14:54 +02:00
Niels 5173c16222 another try 2016-06-07 07:07:42 +02:00
Niels 744bae7fc4 trying to fix Travis 2016-06-07 07:00:31 +02:00
Niels 9e2dfd19e8 minor cleanup 2016-06-07 00:20:53 +02:00
Niels b508d1f1c4 fix proposal for #260 2016-06-06 18:50:39 +02:00
Niels 04e1e7b586 cleanup 2016-05-29 14:56:08 +02:00
Niels aa8aa3ba9f overworked coverity stuffy 2016-05-29 14:06:43 +02:00
Niels 6bdb883b5c ignore build errors for coverity-scan 2016-05-29 13:32:36 +02:00
Niels c0b2c6ea5d removing beta-xcode6.3 for now 2016-05-29 13:06:27 +02:00
Niels 6fed416125 fixed used compiler 2016-05-29 12:57:09 +02:00
Niels b26582c0e9 another try for coverity-scan 2016-05-29 12:29:46 +02:00
Niels 1cc77a5fe5 another try for coverity-scan 2016-05-29 12:15:13 +02:00
Niels 91dfc723be added coverity_scan 2016-05-29 12:07:20 +02:00
Niels 7bdfde4493 added a note about different NDKs (see #219) 2016-05-28 16:06:41 +02:00
Niels 71a7746ccb removed a line 2016-05-25 21:55:03 +02:00
Niels a3f432b3dd added hint to Homebrew 2016-05-18 22:23:35 +02:00
Niels 25d60b7bab Merge pull request #247 from robertmrk/feature/cmake-cleanup
Define CMake/CTest tests
2016-05-18 22:20:45 +02:00
Niels 837617122a fixed #246 2016-05-18 22:17:08 +02:00
Robert Marki 639d63217e Define CMake/CTest tests
Instead of copying the test executable and the JSON files used by
the tests at install time, define CMake/CTest tests for running
the json_unit executable from any build directory with the project's
source directory as its working directory.

- call enable_testing in the main lists file to allow the definition
of tests
- remove install commands from the test directory's lists file
- define two tests
  - json_unit_default for running the default tests by executing
json_unit without any arguments
  - json_unit_all for running all the tests by executing json_unit
with the "*" argument
- update the AppVeyor configuration file to use the new testing method
2016-05-18 11:53:49 +02:00
Niels 0a393b8374 indentation cleanup 2016-05-12 07:34:36 +02:00
Niels 0e0ecb2c14 fixed a warning and update ChangeLog 2016-05-12 00:32:18 +02:00
Niels fb06356856 thanks 2016-05-11 20:58:11 +02:00
Niels 888d022573 Merge pull request #242 from ChrisKitching/outOfTree
Out of tree builds and a few other miscellaneous CMake cleanups.
2016-05-11 20:52:45 +02:00
Niels f1e61896fb fixed a shadow error 2016-05-11 18:43:12 +02:00
Niels db5c9ec9ba fixed issue #239 (-Wconversion warnings) 2016-05-11 17:25:59 +02:00
Niels 91aa4c9def Merge branch 'develop' into feature/issue239 2016-05-11 17:23:01 +02:00
Chris Kitching 0e2f0c4edc Repair appveyor... Horrifyingly
It's sort of gnarly that it's still doing in-tree builds, but I
really, _really_ don't want to get any more friendly with CMake's
Visual Studio generator to work out how to make it stop doing it.

In-tree builds still work, after all, and the goal of this work is
to make out-of-tree builds work as well. Notional horrors like
this will have to wait ;)
2016-05-11 14:02:53 +01:00
Chris Kitching 527a69bb64 Install the test binary and test data. Fixes #241
The resulting install tree, when tests are enabled, looks like this:

```
.
├── cmake
│   ├── nlohmann_jsonConfig.cmake
│   ├── nlohmann_jsonConfigVersion.cmake
│   └── nlohmann_jsonTargets.cmake
├── include
│   └── nlohmann
│       └── json.hpp
└── test
    ├── bin
    │   └── json_unit
    └── data
        ├── json_nlohmann_tests
        │   ├── all_unicode.json
        │   └── bom.json
        ├── json.org
        │   ├── 1.json
        │   ├── ...
        ├── json_roundtrip
        │   ├── roundtrip01.json
        │   ├── roundtrip02.json
        │   └── ...
        ├── json_tests
        │   ├── fail10.json
        │   └── ...
        └── json_testsuite
            └── sample.json
```

It has the property that you can invoke the test binary from the
root of the install tree and the tests work correctly (you no
longer depend on the test binary being run inside the source
tree).

If tests are disabled, the entire `test/` subtree is omitted.
Notice how that yields exactly what you want for using this
library in other projects.

I do not believe I need to update travis due to this change, as the
evil Makefile continues to do in-tree builds. I expect I'll find
out soon enough.
2016-05-11 01:43:42 +01:00
Chris Kitching af76508fe7 Introduce structure to the test/ directory
This introduces a clear separation between test data and test
binaries. Test data is moved into test/data, and the test binaries
move into test/src. A new CMake script specific to building the
tests is introduced in /test to slightly clean up the toplevel
one.

As well as tidying things up, this makes the next step trivial...
2016-05-11 01:30:08 +01:00
Chris Kitching 4e6aacda36 Use definitely-unique target/project name
There exist lots of json libraries, and project/target names must
be globally unique. If someone integrated with this library in a
particularly stupid way, using a generic name like "json" might
cause a problem.
2016-05-11 01:14:56 +01:00
Chris Kitching b6becce8fb Don't use variable for the test target name
I'm not sure that using a variable for target names really helps
with clarity. Unlike paths, target names aren't really something
you change. In a sense, targets are themselves a sort of variable,
so having a variable to name a variable seems just a bit gnarly.
2016-05-11 01:12:56 +01:00
Chris Kitching bf7b6d15c7 Unset execute bit on sample.json 2016-05-11 01:10:29 +01:00
Chris Kitching 6a98a6c964 Add CMake option to disable building the tests (Default builds) 2016-05-11 01:06:32 +01:00
Niels 9ecf83f630 working on #235 2016-05-08 20:28:20 +02:00
Niels 6d8e00ade8 another try to remove a warning 2016-05-08 17:17:17 +02:00
Niels ac3036dc0f Merge branch 'develop' into feature/issue239 2016-05-08 17:07:08 +02:00
Niels fadf286653 added test case for std::bad_alloc 2016-05-08 14:35:32 +02:00
Niels 85a30813c8 removed unnecessary code (numbers must not begin with "+") 2016-05-07 20:22:58 +02:00
Niels 688cd49bdc Merge branch 'feature/json-patch' into develop 2016-05-07 18:41:02 +02:00
Niels c04275966f improved test coverage 2016-05-07 18:33:43 +02:00
Niels 9073b2ca39 hopefully removed some warnings 2016-04-30 16:22:27 +02:00
Niels ea84a85b13 simplified flatten/unflatten examples 2016-04-30 10:39:03 +02:00
Niels a21f8b0c77 added AppVeyor information 2016-04-30 01:21:35 +02:00
Niels 9170740f45 added documentation on Travis compilers 2016-04-30 01:01:41 +02:00
Niels 7c04bc3db6 added name call 2016-04-30 00:43:33 +02:00
Niels be16d005e4 get compiler versions 2016-04-30 00:25:11 +02:00
Niels f4ecceab19 cleanup 2016-04-30 00:12:19 +02:00
Niels 1d3b4dd158 added test cases 2016-04-30 00:03:47 +02:00
Niels 62f81a60d7 hopefully fixed a warning 2016-04-29 21:23:13 +02:00
Niels 82f5332cf4 Merge branch 'develop' into feature/json-patch 2016-04-29 20:50:34 +02:00
Niels 74544b42af removed MinGW compiler (too old) 2016-04-29 20:48:47 +02:00
Niels c019088d3b wrong MinGW binary 2016-04-29 20:35:40 +02:00
Niels b685737d53 added MinGW 2016-04-29 20:18:20 +02:00
Niels ddc5442c91 cleanup 2016-04-29 20:09:41 +02:00
Niels a07cdb14ec don't install valgrind for OSX 2016-04-29 20:01:11 +02:00
Niels 40abeb28d5 Valgrind only for Linux 2016-04-29 20:00:33 +02:00
Niels 68c50073a4 added OSX 2016-04-29 19:46:37 +02:00
Niels ca604c5a2e trying Clang 3.9 2016-04-29 19:37:52 +02:00
Niels 86d7e3090f removed GCC 6, added Clang 3.5 2016-04-29 19:33:43 +02:00
Niels e35805cf3a added GCC 6 and Clang 3.8 to Travis 2016-04-29 19:29:02 +02:00
Niels 86debab3b1 Merge branch 'develop' into feature/json-patch 2016-04-26 20:43:02 +02:00
Niels 9af8f7d094 update after #238 2016-04-26 20:38:01 +02:00
Niels 7dc07b75de Merge branch 'develop' into feature/json-patch 2016-04-26 20:32:24 +02:00
Niels 0f64761663 Merge pull request #238 from robertmrk/cmake-package
Implement additional integration options
2016-04-26 20:31:19 +02:00
Niels 5e0bf75d60 cleanup, test, and diff 2016-04-25 23:17:04 +02:00
Robert Marki 192a692034 Generate package config files in cmake's current binary directory
Generate the config files of the package in CMAKE_CURRENT_BINARY_DIR
instead of CMAKE_BINARY_DIR because the later will refer to the main
project's binary directory if the library is included in the project
using the add_subdirectory command.
2016-04-25 11:55:03 +02:00
Robert Marki b1a2e9a715 Create an install target for the project
- define the project's version in the cmake listfile
- create a config and config version file for the cmake package
- install the json.hpp file and the package's targets, config and
config version files
2016-04-25 10:27:19 +02:00
Robert Marki 30e396043a Export library target and store build directory in package registry 2016-04-25 09:36:05 +02:00
Robert Marki 28f73ed406 Refactor CMake listfile to define an interface imported library
Define the library as an interface imported library so other targets
can use the library as a dependency and use the interface properties
of the library.
2016-04-24 19:56:20 +02:00
Niels 96cfe7463f fixed some warnings 2016-04-24 19:09:12 +02:00
Niels 8d4cf5ef8d oops 2016-04-24 19:04:10 +02:00
Niels fb54e212b6 clean up and added tests 2016-04-24 19:03:33 +02:00
Niels 09e9f6dcd4 implemented "move" 2016-04-24 17:43:27 +02:00
Niels 855cf2307b extended "add" to cope with arrays 2016-04-24 16:51:06 +02:00
Niels 397ada22d3 implemented remove 2016-04-20 16:52:00 +02:00
Niels fa03cf0c63 replace and copy 2016-04-20 15:41:33 +02:00
Niels 70fc5835cb started implementing JSON Patch (RFC 6902) 2016-04-18 22:41:36 +02:00
Niels 3ca1bfdd9d made a function static 2016-04-17 23:41:52 +02:00
Niels f4107d0d9c updated documentation 2016-04-17 23:36:37 +02:00
Niels 9f8da4c650 Merge branch 'feature/json-pointer' into develop 2016-04-17 23:23:34 +02:00
Niels 08c97df420 added examples 2016-04-17 23:18:07 +02:00
Niels 1dee40a969 fixed test case 2016-04-17 22:34:39 +02:00
Niels 6268287940 improved documentation and test coverage 2016-04-17 22:08:21 +02:00
Niels 7034ae2486 improved test coverage 2016-04-17 19:12:12 +02:00
Niels 0835eb293f improved RFC compliance and code coverage 2016-04-17 18:54:54 +02:00
Niels f883a04c87 more documentation 2016-04-17 18:18:49 +02:00
Niels 40e899a819 cleanup and documentation 2016-04-17 17:39:35 +02:00
Niels f834965b44 implemented deflatten function 2016-04-16 20:45:40 +02:00
Niels 007359675b added a flatten function 2016-04-16 16:39:20 +02:00
Niels 3401954f5b cleaned up API 2016-04-16 14:02:14 +02:00
Niels 3a3e064287 Merge branch 'develop' into feature/json-pointer 2016-04-16 12:19:31 +02:00
Niels 76a5a776eb cleanup after #234 2016-04-16 12:19:10 +02:00
Niels 6f0053a254 Merge branch 'support-move-iterators' of https://github.com/robertmrk/json into develop 2016-04-16 12:12:16 +02:00
Niels 94af8abdff overworked reference token parsing 2016-04-13 23:23:54 +02:00
Niels 2cb925c186 adding support for escaped reference tokens 2016-04-13 17:41:19 +02:00
Robert Marki 2197f5f0a6 Make the indirection and dereference operators of iterator const
fixes #233
2016-04-13 13:49:53 +02:00
Niels 726051e9b7 very first draft of a JSON pointer API 2016-04-11 23:17:03 +02:00
Niels 507322e6f2 updated ChangeLog 2016-04-10 19:36:09 +02:00
Niels 15f8c848fa fixed typo and indentation 2016-04-10 18:23:43 +02:00
Niels 170b70f082 Merge pull request #232 from nlohmann/issue228
make serialization locale-independent (fixes #228)
2016-04-07 17:16:58 +02:00
Niels a744c62696 made tests independent of "C" locale 2016-04-05 22:28:27 +02:00
Niels 0b60d970e9 make code independent of concrete locale 2016-04-05 22:12:12 +02:00
Niels 31bccc83b9 fixed locale problems 2016-04-05 21:55:51 +02:00
Niels 43ee70cef8 revert changes to master 2016-04-05 20:47:47 +02:00
Niels 44a8e9bf35 locale-independent dump 2016-04-03 16:33:30 +02:00
Niels 9c233be567 merged #201 2016-04-03 14:08:38 +02:00
Niels 04edafbddc Merge pull request #227 from kevin--/kevin--/noexcept_documentation
fixes #223 by updating README.md
2016-03-30 20:21:35 +02:00
Niels 1baa5a7350 fixed #225 2016-03-30 20:18:34 +02:00
Niels 0951a1f94c Merge pull request #222 from Teemperor/fixAndroid
Added missing cerrno header to fix ERANGE compile error on android
2016-03-30 20:12:55 +02:00
Niels 96443b0b97 added more thanks to the README file 2016-03-30 19:47:08 +02:00
Niels 27530c7840 better notes for Android (manually closes #215) 2016-03-30 19:42:54 +02:00
Niels 888635b749 cleanup after PR #212 and PR #226 2016-03-30 19:23:11 +02:00
Kevin Dixon 3df5337e79 fixes #223 by updating README.md 2016-03-29 21:41:46 -07:00
Niels 54d3cab568 Merge pull request #226 from lv-zheng/fix_int64
Use namespace std for int64_t and uint64_t
2016-03-29 10:35:24 +02:00
Lv Zheng 3e76e61b9c Use namespace std for int64_t and uint64_t
According to the c++11 standard, the declarations are within namespace
scope of the namespace `std'. Add `std::' to avoid unnecessary
requirement of implementations.
2016-03-28 18:11:12 +08:00
Niels 2f63e5fb45 added copyright information to files to make release more self-contained 2016-03-25 17:41:36 +01:00
Raphael Isemann fbc25b080b Added missing cerrno header to fix ERANGE c-error on android 2016-03-10 08:46:26 +01:00
Niels c6a6a024f7 fixes #214 2016-03-06 20:03:05 +01:00
Niels 10a884473e fixed #217 2016-03-04 07:30:08 +01:00
Niels 8ee3d24046 Merge pull request #218 from Annihil/master
Corrected readme
2016-03-04 07:26:27 +01:00
Annihil 78a020354d Corrected readme
Internally, the elements in a map are always sorted by its key following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare).
With string type, the default comparator is alphabetical order, and thus two come after three.
2016-03-02 02:01:40 +01:00
Niels 53879f9c99 cleanup 2016-02-21 08:17:11 +01:00
Niels 502cedf70b Merge pull request #213 from whackashoe/patch-1
Create PULL_REQUEST_TEMPLATE.md
2016-02-21 08:15:46 +01:00
Jett LaRue df3ab06f2e Create PULL_REQUEST_TEMPLATE.md 2016-02-20 16:22:46 -06:00
Niels f965c4c35b improved code coverage 2016-02-14 22:56:51 +01:00
Niels d869b0a387 updated online documentation 2016-02-14 22:28:56 +01:00
Niels 3a92559fa9 cleanup 2016-02-14 22:24:45 +01:00
Niels 09654b3104 Merge pull request #208 from nlohmann/noexcept
fixed noexcept; added constexpr
2016-02-14 22:18:39 +01:00
Niels f160f33fb5 update from master 2016-02-14 21:44:00 +01:00
Niels 7f4736b546 added serialization to fuzz testing 2016-02-14 21:36:56 +01:00
Niels a3eecdc383 updated Catch to v1.3.4 2016-02-14 21:36:43 +01:00
Niels 153e105164 cleanup after #207 2016-02-14 18:38:29 +01:00
Niels ec098ffcc2 Merge pull request #207 from msm-/afl-fuzz
add support for afl-fuzz testing
2016-02-14 17:24:54 +01:00
Niels 49dc2dff68 fixed error when compiled with Clang 2016-02-14 16:58:24 +01:00
Niels 836fdfedf2 fixed an error in MSVC 2016-02-14 16:53:32 +01:00
Niels a69b1a6f0b added noexcept and constexpr 2016-02-14 16:42:48 +01:00
Michael Macnair 9e500b49ac Add support for afl-fuzz testing
"make fuzz" creates a simple executable that de-serialises stdin
and re-serialises to stdout.
"make fuzz_testcases" extracts the smaller json test cases into
a testcases directory.

The library can then be fuzzed as follows:
    CC=afl-clang-fast make fuzz
    make fuzz_testcases
    mkdir out
    afl-fuzz -i testcases -o out ./fuzz
2016-02-12 09:35:08 +00:00
Niels 61fe90f998 Merge pull request #205 from nlohmann/issue204
replaced ssize_t occurrences with auto (fixes #204)
2016-02-10 21:41:55 +01:00
Niels a831c787df try to replace std::ptrdiff_t with auto (for #204) 2016-02-10 21:19:31 +01:00
Niels 4cc4b26dd2 try to replace ssize_t occurrences with std::ptrdiff_t (for #204) 2016-02-10 21:09:52 +01:00
Niels 1cc4717582 tried Clang 3.9 2016-02-09 21:26:40 +01:00
Niels be20555985 removed gitter 2016-02-07 17:24:51 +01:00
Niels 236b7afff5 updated and fixed online version 2016-02-07 15:07:17 +01:00
Niels fdfb39d949 improved documentation 2016-02-07 14:55:29 +01:00
Niels 3b776c08c7 clarified documentation 2016-02-07 10:45:52 +01:00
Niels 8b1a777d36 reverted change wrt. Erasable concept 2016-02-05 22:37:28 +01:00
Niels 2ff2e10660 checking Erasable concept 2016-02-05 22:30:37 +01:00
Niels ae5bd307a2 improved documentation 2016-02-05 22:30:25 +01:00
Niels 2c720b26ab added a constructor from an input stream 2016-02-05 19:24:42 +01:00
Niels 104c4b5286 improve code coverage 2016-01-31 15:04:38 +01:00
Niels 6aa881988d improved documentation 2016-01-31 13:05:39 +01:00
Niels 22127a4b85 moved documentation to index markdown file 2016-01-30 22:05:01 +01:00
Niels 740239cef8 added a note about GCC 4.8 (#163) 2016-01-30 21:17:08 +01:00
Niels 36719fdb18 using re2c 0.16 (minimized automaton) 2016-01-30 20:33:31 +01:00
Niels 9d063d90e3 removed "using namespace" from examples 2016-01-30 20:23:14 +01:00
Niels ade2f7c92d updated ChangeLog 2016-01-30 16:51:53 +01:00
Niels 2224435f9b cleanup after #200 2016-01-30 13:36:15 +01:00
Niels cd44e43457 Merge pull request #200 from twelsby/issue199
Fixed issue #199 - Small bugs in json.hpp (get_number) and unit.cpp (non-standard integer type test)
2016-01-30 13:32:22 +01:00
Trevor Welsby 561accb068 Fixed issue #199 2016-01-30 12:41:12 +10:00
Niels ff6f723195 removed token 2016-01-26 23:30:51 +01:00
Niels 3dfa56795f added note 2016-01-26 23:27:07 +01:00
Niels 1c80c2231f linked releases in ChangeLog 2016-01-26 23:10:52 +01:00
Niels 89b07bd3af added (generated) changelog 2016-01-26 22:59:57 +01:00
Niels 91c58a77a1 added Gitter to Travis 2016-01-26 21:49:20 +01:00
Niels fb239fe645 trying Gitter 2016-01-26 21:42:51 +01:00
Niels 2468631dc9 overworked examples 2016-01-26 20:07:03 +01:00
Niels 707732a53e clean up after #193 2016-01-26 19:50:49 +01:00
Niels e46cc6327f Merge pull request #193 from twelsby/issue178
Issue #178 - Extending support to full uint64_t/int64_t range and unsigned type (updated)
2016-01-26 19:40:16 +01:00
Niels d338042e3e added note to warn about floating-point exceptions (#181) 2016-01-26 19:21:46 +01:00
Niels 11ae1d0f09 cleanup after #196 2016-01-26 19:13:03 +01:00
Niels 077fb1d540 Merge pull request #196 from twelsby/issue195
Issue #195 - update Travis to Trusty due to gcc/clang strtod() bug
2016-01-26 19:12:36 +01:00
Niels b630ce0e78 thanks 2016-01-26 19:11:58 +01:00
Niels 8deaabb289 Merge pull request #197 from m-click/fix_broken_link
Fix broken link
2016-01-26 19:10:46 +01:00
Volker Diels-Grabsch 08fd6dbf98 Fix broken link 2016-01-26 15:22:15 +01:00
Trevor Welsby 2de94365de Revert to llvm-toolchain-precise-* due to Travis white-list issue 2016-01-26 09:14:43 +10:00
Trevor Welsby a4a88b1b7d Issue #195 - update Travis to Trusty due to gcc/clang strtod() bug 2016-01-26 08:36:18 +10:00
Niels 2b13711009 updated online version 2016-01-24 23:02:28 +01:00
Niels c09d03fba7 fixed documentation 2016-01-24 22:43:00 +01:00
Niels 31093694ce fixed version number 2016-01-24 22:21:27 +01:00
Niels aee99b362d some editing 2016-01-24 19:24:06 +01:00
Trevor Welsby 0f28c69499 Merge upstream commits and resolve conflicts 2016-01-25 02:48:38 +10:00
Trevor Welsby 281492c581 Merge upstream commits and resolve conflicts 2016-01-25 02:42:20 +10:00
Niels 54a4139157 cleanup after #191 2016-01-24 17:33:46 +01:00
Trevor Welsby 4620960b72 Disable problematic test for GCC/clang, remove debug dump from unit.cpp 2016-01-25 02:22:46 +10:00
Niels ad5d1dabb2 Merge pull request #191 from twelsby/issue186
Fixed Issue #186 - add strto(f|d|ld) overload wrappers, "-0.0" special case and FP trailing zero
2016-01-24 17:21:22 +01:00
Trevor Welsby 81b7079255 Kill unused argument warnings in GCC/clang 2016-01-25 02:13:39 +10:00
Trevor Welsby 19918b948d Fix typo in preprocessor defined/!defined 2016-01-25 02:07:49 +10:00
Niels 9584a99a43 added issue stats 2016-01-24 17:06:36 +01:00
Trevor Welsby 421affd06e Merge upstream commits and resolve conflicts 2016-01-25 02:01:01 +10:00
Trevor Welsby 4d6985d4e2 Disable problematic test for GCC/clang, remove debug dump from unit.cpp 2016-01-25 01:53:32 +10:00
Niels dfb01c659b added more comments 2016-01-24 16:42:45 +01:00
Niels 3245a0dc06 fixed #194 2016-01-24 16:42:13 +01:00
Trevor Welsby 12ef668335 Merge upstream commits and resolve conflicts 2016-01-25 01:15:13 +10:00
Trevor Welsby d7ef2ccffd Issue #178 - fully support int64_t/uint64_t numbers, add unsigned type 2016-01-25 01:04:37 +10:00
Niels 8b6e0dc02d small addition 2016-01-24 13:28:16 +01:00
Niels d7d1e55648 applied include-what-you-use 2016-01-24 13:28:08 +01:00
Niels 8a0490a011 cleanup 2016-01-24 13:04:55 +01:00
Niels e00b00fea8 Merge pull request #190 from twelsby/issue185
fixed #185 - remove approx() and use #pragma to kill warnings
2016-01-24 12:55:40 +01:00
Niels 600ad330c5 cleanup after PR #189 2016-01-24 11:00:54 +01:00
Niels 21a44da89d Merge pull request #189 from twelsby/issue171
Fixed Issue #171 - added two extra template overloads of operator[] for T* arguments
2016-01-24 10:47:26 +01:00
Trevor Welsby f79d52b973 DEBUG ONLY: DUMP INFO FROM TRAVIS 2016-01-24 19:15:30 +10:00
Trevor Welsby c1f5f0451d Add workaround for gcc < 5 not supporting std::defaultfloat 2016-01-24 17:54:50 +10:00
Trevor Welsby bd8db5d40e Remove VS induced tabs 2016-01-24 17:15:44 +10:00
Trevor Welsby a1c6f16bd3 Fix Issue #186 - add overload wrappers for strto(f|d|ld) 2016-01-24 17:00:11 +10:00
Trevor Welsby 3a1403409f Issue #185 - remove approx() and use #pragma to kill warnings 2016-01-23 17:45:30 +10:00
Trevor Welsby bd0f3001c6 Fix typo in new unit.hpp comments 2016-01-23 17:31:58 +10:00
Trevor Welsby 7e3245786c Fixed issue #171 - added extra operator[] template overloads 2016-01-23 17:03:45 +10:00
Trevor Welsby 9de14a4861 Fixed issue #167 - removed operator ValueType() condition for VS2015 2016-01-23 16:34:15 +10:00
Niels f854410542 added a note wrt. Valgrind (#175) 2016-01-20 21:20:41 +01:00
Niels 5c4624c351 wishlist 2016-01-20 21:15:10 +01:00
Niels a04bd4f851 cleanup after #184 2016-01-20 21:14:58 +01:00
Niels 663ad13fc3 Merge pull request #184 from dariomt/master
Implementation of get_ref()
2016-01-20 20:58:44 +01:00
dariomt db3c7fdb96 added missing template keyword (required by clang) 2016-01-19 16:20:27 +01:00
dariomt e2f0e8b945 added missing typename (required by clang/gcc) 2016-01-19 14:56:07 +01:00
dariomt 4d079d135e replicate code changes into re2c file 2016-01-18 11:32:24 +01:00
dariomt e1645a09e9 Merge branch 'master' of https://github.com/nlohmann/json 2016-01-18 10:08:58 +01:00
Niels 72e33eec1a thanks 2016-01-15 08:24:44 +01:00
Niels 8968885c61 Merge pull request #182 from nibroc/master
Fixed some typos in CONTRIBUTING.md
2016-01-15 07:21:07 +01:00
Corbin Hughes 8ecccf8628 Fixed some typos in CONTRIBUTING.md 2016-01-14 22:36:39 -06:00
Niels c0bb5a56eb added note on assertions (#168) 2016-01-13 21:08:46 +01:00
Niels a05f27867b fixed wrong file name 2016-01-13 20:37:05 +01:00
Niels 832fe49bc1 fixed lists 2016-01-13 20:26:47 +01:00
Niels 57e018483a it's 2016 already... 2016-01-13 20:19:05 +01:00
Niels 1741e58eb5 contribution guidelines (#175) 2016-01-13 20:18:06 +01:00
Niels 4511145d3d removing unused catch variables (fixes #180) 2016-01-13 19:19:35 +01:00
Niels 151d43f63e fixing numerous typos (fixes #179) 2016-01-13 19:14:33 +01:00
Niels 4a452f11f9 added assertions (#168) 2016-01-03 17:05:27 +01:00
Niels d27c8a8ea8 reverting OSX 2016-01-02 16:49:56 +01:00
Niels fb7ff414ad more Valgrind information 2016-01-02 16:42:45 +01:00
Niels 2d48a36f5c trying Travis and OSX 2016-01-02 16:37:40 +01:00
Niels b4bb3afb65 removed clang 3.8 2016-01-02 15:42:56 +01:00
Niels 4a87ed4441 trying Clang 3.8 2016-01-02 15:34:34 +01:00
Niels 33abe87407 forgot version number 2016-01-02 15:30:12 +01:00
Niels dbf58ae9c0 trying to add Clang 3.7 toolchain 2016-01-02 15:24:13 +01:00
Niels 7614aa31c0 cleanup 2016-01-02 13:07:22 +01:00
Niels 9b07504e23 fix for #166 2016-01-01 18:33:58 +01:00
Niels 3905406f9c removed an unnecessary cast (fixed #162) 2015-12-29 12:30:05 +01:00
Niels aca6a3b373 version number 2015-12-28 15:04:15 +01:00
Niels cb5581392a preparing 1.0.0 release 2015-12-28 14:51:57 +01:00
Niels 80cdecaadd fixed a cppcheck warning 2015-12-27 18:07:21 +01:00
Niels d80bbffc78 minor cleanup 2015-12-27 17:58:36 +01:00
Niels 7371c71d2a using CHECK_THROWS_WITH to check exceptions (#160) 2015-12-27 15:30:30 +01:00
Niels d6b8830e03 more work on exceptions (#160) 2015-12-26 13:17:32 +01:00
Niels dc8ab92552 more tests for exceptions (#160) 2015-12-25 13:04:40 +01:00
Niels 76e5e29eda overworked exceptions and tests (#160) 2015-12-25 11:46:18 +01:00
Niels 8620583cf9 cleanup 2015-12-23 12:05:57 +01:00
Niels fcbd984e0f cleanup 2015-12-23 08:44:34 +01:00
Niels 70493a10d1 iterator_wrapper for const objects (#83) 2015-12-23 08:21:29 +01:00
Niels 00f9296db5 some cleanup for #83 2015-12-22 18:07:51 +01:00
Niels 67c2d90a21 working on #160 2015-12-22 13:27:40 +01:00
Niels 4351698c83 re-adding const version operator[] (#135, #159)
It was a good idea to implement a const version of operator[] it in the
first place. I was a pity that this implementation was flawed. It was a
mistake to remove the const version completely. This commit
re-introduces the const version. My apologies for all the inconvenience.
2015-12-21 08:42:42 +01:00
Niels 9def0186be upgraded Catch to v1.3.1 2015-12-20 15:42:01 +01:00
Niels 457bfc2401 work on #144 2015-12-20 15:30:07 +01:00
Niels 1adb9d62dd fixed #156 2015-12-17 16:52:38 +01:00
Niels ac4d4a0f66 fixed compilation error and fixed shadow warnings 2015-12-17 16:22:15 +01:00
Niels 07033f67a5 some cleanup and more documentation 2015-12-17 15:49:33 +01:00
Niels fb972e845b show reference to source code in documentation 2015-12-16 12:10:12 +01:00
Niels 6ac89df54d fix for #127 2015-12-16 12:09:59 +01:00
Niels a615598b14 cleanup documentation; started added versions 2015-12-15 19:42:32 +01:00
Niels 1df5d726d9 undid the fix for #136 2015-12-15 18:34:07 +01:00
Niels cd04a7d3e9 fix for #133
added value() function to get object value at given key or a default
value if key does not exist
2015-12-15 08:38:54 +01:00
Niels 2ba901bbf6 cleanup 2015-12-14 21:23:21 +01:00
Niels 5bc1b65676 clean up (for #154) 2015-12-14 16:58:49 +01:00
Niels 258f04c561 fixed #154 (no more warnings for incomplete switches) 2015-12-14 16:32:37 +01:00
Niels a70a7a8001 fixed #135: operator[] now only works on nonconst JSON objects 2015-12-13 11:26:55 +01:00
Niels c767f464bb dropped GCC 4.8 support (due to #110) 2015-12-08 18:12:34 +01:00
Niels 9da8770f3a ignore UTF-8 byte order mark (fixes #152) 2015-12-07 22:27:53 +01:00
Niels e0d334c4f1 added a comment (see #109) 2015-12-07 21:53:32 +01:00
Niels d6771ac79d corrected a username 2015-12-07 21:50:27 +01:00
Niels d9432aa168 Merge pull request #124 from emvivre/master
remove invalid parameter '-stdlib=libc++' in CMakeLists.txt
2015-12-07 21:11:58 +01:00
Niels 22bc022745 added change from #140 2015-12-07 21:05:21 +01:00
Niels 72476b4226 cleanup after #153 2015-12-07 20:38:16 +01:00
Niels f36f316fc7 Merge pull request #153 from whackashoe/remove_sprintf
Replace sprintf with hex function, this fixes #149
2015-12-07 20:35:43 +01:00
Niels 6f8e36ac3d fixes #136 2015-12-06 17:33:52 +01:00
Jett 14d8a91f73 Replace sprintf with hex function, this fixes #149 2015-11-19 00:30:00 -06:00
Niels c013223276 Merge pull request #146 from robertmrk/surrogate-pair-parsing-fix
Fix character skipping after a surrogate pair
2015-11-14 08:22:04 +01:00
Robert Marki ec7a1d8347 Fix character skipping after a surrogate pair
In a string the first character following a surrogate pair is skipped by the
lexer, but the rest of the string is parsed as usual.
2015-11-13 13:13:46 +01:00
Niels 3948630374 Merge pull request #130 from dariomt/patch-1
removed stream operator for iterator, resolution for #125
2015-10-23 18:42:10 +02:00
Niels 8f379ef3eb Merge pull request #137 from dariomt/patch-3
Detect correctly pointer-to-const
2015-10-20 22:31:15 +02:00
dariomt 652e1caa76 Apply same change to the re2c file 2015-10-19 12:34:10 +02:00
dariomt 8162a6e3a3 Apply same change to the re2c file 2015-10-19 12:26:38 +02:00
Niels 746c1a7142 cleanup 2015-10-17 12:51:59 +02:00
Niels 73632377bf Merge pull request #131 from dariomt/patch-2
disabled "CopyAssignable" test for MSVC in Debug mode, see #125
2015-10-17 12:41:20 +02:00
dariomt 4b8a822f33 Merge branch 'get_ref' 2015-10-16 16:42:03 +02:00
dariomt 95090a7ddd Merge branch 'patch-2' 2015-10-16 16:40:57 +02:00
dariomt 04cc7d5a05 doh! disable test correctly only for MSVC 2015-10-16 16:36:34 +02:00
dariomt 5198e1f2e4 removed const in get_ptr() by accident 2015-10-16 15:45:47 +02:00
dariomt bd2783f45c Added get_ref()
Same as get_ptr() but for references.
If the type is incompatible it throws (get_ptr() returns null).
Implemented in terms of get_ptr().
2015-10-16 15:23:57 +02:00
Dario Menendez 8f97e99feb Merge remote-tracking branch 'origin/patch-3' 2015-10-16 11:23:19 +02:00
Dario Menendez 8d53c5e06f Merge remote-tracking branch 'origin/patch-2' 2015-10-16 11:22:57 +02:00
dariomt b342e1207c Detect correctly pointer-to-const
The intention of the current code is to detect a pointer-to-const but instead it is detecting a const-pointer. See #134
2015-10-16 11:11:16 +02:00
dariomt 9d45aafc2c disabled "CopyAssignable" test for MSVC in Debug mode, see #125
STL iterators used by json::iterator don't pass this test in Debug mode.
The test does pass in Release mode, so I felt the best thing to do was selectively disable that test.
2015-10-07 18:31:08 +02:00
dariomt 55cbd903e8 removed stream operator for iterator, resolution for #125
It doesn't really make sense to stream an iterator.
Besides, this was causing trouble in MSVC in Debug mode (see #125)
2015-10-07 17:50:53 +02:00
Niels 57de1d602e Cleanup 2015-10-03 13:16:59 +02:00
Niels 2550d29ded Merge pull request #122 from d-frey/patch-1
exception-safe object creation, fixes #118
2015-10-03 12:29:26 +02:00
Niels 589dc2180a Merge pull request #120 from silverweed/patch-1
Overload parse() to accept an rvalue reference
2015-10-03 10:43:16 +02:00
Niels 4eac295211 Merge pull request #115 from whoshuu/patch-1
Use the right variable name in doc string
2015-10-03 10:41:26 +02:00
Niels b3ff862afc Merge pull request #121 from ColinH/master
Fix small oversight.
2015-10-03 10:39:14 +02:00
Niels 83d068c32c Merge pull request #126 from d-frey/patch-2
Remove superfluous inefficiency
2015-10-03 10:38:18 +02:00
Niels 99261bf39c Merge pull request #129 from dariomt/master
fixed typos in comments for examples
2015-10-03 10:36:35 +02:00
Dario Menendez 260745810d fixed typos in comments for examples 2015-10-02 15:57:40 +02:00
Daniel Frey 1c43789682 Remove superfluous inefficiency 2015-09-25 20:08:35 +02:00
emvivre 4f27004dd5 remove invalid parameter '-stdlib=libc++' in CMakeLists.txt 2015-09-22 16:57:18 +02:00
Daniel Frey f7fb405564 exception-safe object creation, fixes #118 2015-09-20 20:06:33 +02:00
Huu Nguyen 2d7f1542b1 Use the right variable name in doc string 2015-09-20 07:27:34 -07:00
silverweed 8fdd20cdda Overload parse() to accept an rvalue reference 2015-09-20 16:15:55 +02:00
Colin Hirsch c6c37d00d1 Fix small oversight. 2015-09-20 15:04:51 +02:00
Niels 0a81353989 reverted changes 2015-08-22 10:47:14 +02:00
Niels b9592bd2d6 more compilers 2015-08-22 10:43:04 +02:00
Niels 067e33a7ed removed failing compilers 2015-08-21 19:12:06 +02:00
Niels bb0d01e597 better compiler matrix 2015-08-21 19:05:47 +02:00
Niels 941c84e17d debugging 2015-08-14 15:30:06 +02:00
Niels 3c8c2766c1 debugging 2015-08-14 15:20:50 +02:00
Niels 23f70b47ad Appveyor fix 2015-08-14 15:09:16 +02:00
Niels bd5d96c456 minor change 2015-08-14 14:56:58 +02:00
Niels b58a93b8dd merged #111 2015-08-14 14:45:13 +02:00
Niels 6f2da1a39a try to avoid MSVC bug (https://connect.microsoft.com/VisualStudio/feedback/details/797682/c-decltype-of-class-member-access-incompletely-implemented) 2015-08-13 10:24:28 +02:00
Niels fadccc34eb fixed iterator_wrapper 2015-08-13 10:08:55 +02:00
Niels 66ec58639b removed failing tests 2015-08-06 23:02:52 +02:00
Niels 2707733920 fixed off-by-one error 2015-08-06 22:53:16 +02:00
Niels b0eb34394c added test cases for #83 2015-08-06 22:36:08 +02:00
Niels 11ae6da6d9 reverted “fix” for issue #107 2015-08-06 22:35:56 +02:00
Niels b431203fe8 fixed travis script 2015-08-06 21:33:24 +02:00
Niels 2c3259320d addressed locale-issues #107 2015-08-04 18:12:11 +02:00
Niels c910853304 fixed build 2015-08-02 21:49:42 +02:00
Niels b00e627c30 fixed build 2015-08-02 21:47:11 +02:00
Niels 9355dce063 fixed build 2015-08-02 21:40:25 +02:00
Niels e64dc532ab fixed build 2015-08-02 21:35:07 +02:00
Niels b5a05e1121 add a test for the iterator_wrapper 2015-08-02 21:27:02 +02:00
Niels c974e32677 fixed the build 2015-07-30 23:02:55 +02:00
Niels 8eb32084b4 code for #83 (no tests yet) 2015-07-30 21:32:18 +02:00
Niels a26e44d66e prepare 1.0.0-rc1 2015-07-26 20:44:55 +02:00
Niels 359cf7993f closed #75
minor changes, but the core idea remains the same
2015-07-26 18:41:58 +02:00
Niels c8ced4ecbc cleanup 2015-07-26 10:59:17 +02:00
Niels eb782770de removed Clang 3.7 2015-07-26 10:46:15 +02:00
Niels faac3c47c5 fixed travis 2015-07-26 10:41:49 +02:00
Niels 5993ff9976 updated catch 2015-07-26 10:41:38 +02:00
Niels 4c31de262e cleanup 2015-07-26 10:17:51 +02:00
Niels 77e6af0593 cleanup 2015-07-24 22:50:22 +02:00
Niels 0608e2d3e0 added g++-mingw-w64-i686 2015-07-24 22:43:00 +02:00
Niels d9a2077a0e only calculate coverage for GCC 4.9 2015-07-24 22:41:12 +02:00
Niels 3af829ef02 try 2015-07-24 22:29:03 +02:00
Niels 6a0be8b81c llvm source 2015-07-24 22:21:30 +02:00
Niels 9d01160ca8 cleaned llvm sources 2015-07-24 22:19:14 +02:00
Niels 004bb1e952 more llvm sources 2015-07-24 22:16:24 +02:00
Niels 82940483c3 sources for llvm 2015-07-24 22:14:16 +02:00
Niels 76bb61b544 set compiler flag 2015-07-24 22:11:09 +02:00
Niels 3b1c3fb77f added clang 2015-07-24 22:08:29 +02:00
Niels 48ad40607c fix for environment 2015-07-24 22:03:45 +02:00
Niels af5efeeff6 try env 2015-07-24 22:00:48 +02:00
Niels 56f1db2996 added CXX 2015-07-24 21:54:38 +02:00
Niels a4671428ca wrong sources 2015-07-24 21:52:56 +02:00
Niels 2ef7be5faf wrong sources 2015-07-24 21:51:01 +02:00
Niels 25293a4ca6 added missing source 2015-07-24 21:46:46 +02:00
Niels 276444113c local installation 2015-07-24 21:43:07 +02:00
Niels f5d2efdbd8 move to new Travis infrastructure 2015-07-24 21:41:07 +02:00
Niels 300fba6388 fixed Windows build 2015-07-19 13:33:03 +02:00
Niels 623c03bc49 some cleanup 2015-07-19 12:41:46 +02:00
Niels 818ae5a524 updated documentation to show off MSVC support 2015-07-16 22:37:54 +02:00
Niels 92fffaa872 cleanup 2015-07-16 19:53:42 +02:00
Niels afb17d7fac typo... 2015-07-16 19:39:18 +02:00
Niels c89ca716c5 switch off optimizations in MSVC 2015-07-16 19:32:19 +02:00
Niels a63c794521 some changes to Appveyor 2015-07-16 19:04:51 +02:00
Niels 5084159048 added changes from #105: MSVC fixes
- additionally, switch off optimization flags to maybe allow build to
complete on AppVeyor
2015-07-16 18:45:19 +02:00
Niels e007f02c54 updated readme 2015-07-14 21:24:29 +02:00
Niels 5c813b614f closes #104 and integrates code from #93
Iterators are now implemented via const_iterators and reverse_iterator
and const_reverse_iterator now share a template class. Thanks a lot!
2015-07-14 21:21:08 +02:00
Niels 1c8d5dc211 added another insert function 2015-07-12 22:47:08 +02:00
Niels 092bf39f53 added test case 2015-07-12 20:40:46 +02:00
Niels 186aefb8f2 added first insert functions 2015-07-12 18:28:23 +02:00
Niels b2efd50a03 more documentation 2015-07-12 17:08:51 +02:00
Niels 5e1d0f1592 more documentation and some cleanup 2015-07-12 14:49:37 +02:00
Niels c012b29ae5 worked on #102: more documentation and examples 2015-07-08 16:55:29 +02:00
Niels 19d550c044 new implementation for (const_)reverse_iterator to cope with issue #93 2015-07-07 23:31:43 +02:00
Niels 12d174d424 fixed #100 2015-07-06 23:21:54 +02:00
Niels e070aed8a7 cleanup 2015-07-06 21:12:50 +02:00
Niels 2bc5d893c8 refactored generic iterator into a new class primitive_iterator_t 2015-07-05 22:22:15 +02:00
Niels 82a6995306 fixed #101 2015-07-01 23:08:54 +02:00
Niels abd741708d more tests 2015-06-30 00:12:18 +02:00
Niels 55fe3807c9 small README fix 2015-06-29 23:20:33 +02:00
Niels 5ae2babf61 add online examples 2015-06-29 23:02:41 +02:00
Niels 540c58964d closed #91 2015-06-29 20:53:01 +02:00
Niels 48c4f4d05d more documentation 2015-06-28 19:32:09 +02:00
Niels 7d9cfb1b32 added documentation for erase functions 2015-06-28 15:49:40 +02:00
Niels 862e7000f4 fixed #94 2015-06-28 14:39:52 +02:00
Niels 3f6b10733b addressed static analysis warnings #94 2015-06-28 14:02:47 +02:00
Niels c58c5aa8c9 fixed #97
- added functions is_structured() and is_primitive()
- updated documentation
- updated test cases
2015-06-27 18:43:11 +02:00
Niels 3ffedea5c4 minor changes 2015-06-25 00:40:16 +02:00
Niels 5bad95f48e reset travis file 2015-06-24 23:08:40 +02:00
Niels aea2040d42 try travis matrix 2015-06-24 22:49:35 +02:00
Niels 6e6dd5f45d added test cases for the last uncovered lines 2015-06-24 15:46:50 +02:00
Niels 40312fb07b worked on #91
- implemented `get_ptr` function to return pointer to value member
- overworked `get` function to support pointer types
- added test cases
- added documentation (see
http://nlohmann.github.io/json/classnlohmann_1_1basic__json.html) with
examples
2015-06-24 15:16:32 +02:00
Niels 457572184c more documentation
In this commit, also the semantics for values skipped via the parser
callback has changed. Now, the top-level value is returned as “null”
instead of “discarded”.
2015-06-24 12:15:51 +02:00
Niels 48545f5b18 more documentation 2015-06-22 23:21:49 +02:00
Niels f1c9aa26c4 update Travis badge 2015-06-22 21:50:24 +02:00
Niels 844bfd39b5 more documentation 2015-06-22 21:44:20 +02:00
Niels 27b0a4d170 ... 2015-06-21 23:17:58 +02:00
Niels c43047e5f6 added codecov 2015-06-21 23:10:15 +02:00
Niels 88445fd96b fixed doxygen badge 2015-06-21 23:07:13 +02:00
Niels 8e97e46f50 update README badges 2015-06-21 23:05:50 +02:00
Niels 891b8f33c1 more documentation 2015-06-21 22:56:03 +02:00
Niels c85dbef98f more documentation 2015-06-21 22:42:32 +02:00
Niels 770b9820fe target to update documentation 2015-06-21 21:51:23 +02:00
Niels 91c330ae01 reorganized repo 2015-06-21 21:24:03 +02:00
Niels 4bb5126502 more documentation 2015-06-21 18:30:08 +02:00
Niels d972483b33 overworked documentation configuration 2015-06-21 13:39:10 +02:00
Niels f6040ea3bc minor change 2015-06-21 13:16:52 +02:00
Niels e0fa56f84f clean up 2015-06-21 13:14:39 +02:00
Niels 332b10998a clean up 2015-06-21 13:12:17 +02:00
Niels 099030baeb added alias __basic_json 2015-06-21 13:04:03 +02:00
Niels 022c11bf86 broke Makefile 2015-06-21 12:48:18 +02:00
Niels d200abfb5f automatic commit 2015-06-21 12:47:35 +02:00
Niels e289eada49 added target to update Doxygen 2015-06-21 12:45:46 +02:00
Niels 3a5b50d614 removed coverity_scan from travis file 2015-06-21 12:03:59 +02:00
Niels 0dd3ce742b forgot branch_pattern 2015-06-21 11:48:45 +02:00
Niels 3e28c5ff8f commit to trigger build 2015-06-21 11:35:54 +02:00
Niels d818bec6ac more documentation 2015-06-21 11:29:32 +02:00
Niels 70976e2b9c testing poverty 2015-06-21 11:29:24 +02:00
Niels c40e85920f more documentation 2015-06-21 09:44:12 +02:00
Niels bb13c931b3 more documentation 2015-06-21 02:14:01 +02:00
Niels e63c508172 overworked doxygen 2015-06-21 00:59:33 +02:00
Niels 0abac59291 mentioned Clang 3.7 2015-06-20 17:45:59 +02:00
Niels 4019380a8a forgot a header for MSVC 2015-06-20 17:45:52 +02:00
Niels 4fb825dbce fixed compiler warnings 2015-06-20 15:47:37 +02:00
Niels bd8150c58e updated Catch 2015-06-20 15:47:26 +02:00
Niels bf423363bd build in release mode on appveyor (from #88) 2015-06-20 15:13:45 +02:00
Niels 719cc9e4d7 removed dependent to RTTI 2015-06-20 14:57:08 +02:00
Niels 18cd30d38d minor iterator refactoring (from #88) 2015-06-20 14:29:34 +02:00
Niels 23c904aca8 added fix for ssize_t for MSVC 2015-06-20 14:25:49 +02:00
Niels 4f92731823 remove warnings on unit tests (from #88) 2015-06-20 14:16:57 +02:00
Niels 64c467e940 fix warnings possible loss of data (from #88) 2015-06-20 14:15:15 +02:00
Niels 29e8ca64bd applied a part of #88 2015-06-20 14:13:48 +02:00
Niels dd3ffc1064 fixed issue #93 2015-06-19 08:11:48 +02:00
Niels 51edad3962 fixed #89 without breaking #71 2015-06-15 19:45:25 +02:00
Niels 8e9a711996 closes #90 2015-06-15 16:37:49 +02:00
Niels 1375162562 exclude Unicode tests from Valgrind to avoid timeout 2015-06-15 05:46:12 +02:00
Niels 2e9a13bd88 added extensive Unicode tests 2015-06-14 23:17:49 +02:00
Niels 6fb829062c some maintenance
- unified used exception types
- removed any camel case names
2015-06-14 19:35:20 +02:00
Niels bc55e496de test suite is not portable :-( 2015-06-13 13:01:10 +02:00
Niels bd0cb65b7a fixed more float parsing cases 2015-06-13 12:42:18 +02:00
Niels 7c579f11e5 some cleanup after #87 2015-06-13 10:29:43 +02:00
Niels a8339894b2 Merge pull request #87 from ahamez/master
Keyword 'inline' is useless when member functions are defined in headers
2015-06-13 10:27:24 +02:00
Alexandre Hamez a8aced74bc inline is useless when member functions are defined in headers
See https://isocpp.org/wiki/faq/inline-functions#inline-member-fns-more
2015-06-12 10:08:57 +02:00
Niels 7f25511242 change from #86 2015-06-11 18:10:12 +02:00
Niels bab7e9667f added badge for license 2015-06-11 18:08:00 +02:00
Niels 6d8a4aea98 Merge pull request #86 from ahamez/master
Remove useless typename
2015-06-11 18:01:06 +02:00
Alexandre Hamez 41e9e000bf Remove useless typename
Avoid a warning with GCC 4.9:

son.hpp:2361:49: warning: declaration 'struct std::bidirectional_iterator_tag' does not declare anything
         using iterator_category = typename std::bidirectional_iterator_tag;
                                                 ^
2015-06-09 13:31:10 +02:00
Niels 2d26d85c2b some cleanup 2015-06-08 16:35:38 +02:00
Niels d3b0f207b0 Merge pull request #85 from ahamez/master
Avoid warning with Xcode's clang
2015-06-08 16:32:37 +02:00
Alexandre Hamez f17733b859 Directly return ostream 2015-06-08 11:39:32 +02:00
Alexandre Hamez c49d83172f Avoid warning with Xcode's clang 2015-06-08 11:38:52 +02:00
Niels adc065d328 included fixes for MSVC (see #62)
94de11e, f673c8d, 540b763
2015-06-04 21:02:16 +02:00
Niels 29512ae989 added test case for #82 2015-06-04 20:07:33 +02:00
Niels b8d05f72ea fixed float serialization (#81 and #80) 2015-06-04 19:43:29 +02:00
Niels 266399d8e5 fixed MinGW compilation (#81 and #80) 2015-06-04 08:31:13 +02:00
Niels 5f4fd0b6a2 reset 2015-06-03 23:44:45 +02:00
Niels 9dbb4402fb improved performance for dump() 2015-06-03 23:34:10 +02:00
Niels cb873a42ed added Benchpress benchmarks 2015-06-02 23:57:45 +02:00
Niels f5470d47ff made array static constexpr (#79) 2015-06-02 21:27:49 +02:00
Niels afc7f2388e fixed typo (#74) 2015-06-02 21:24:03 +02:00
Niels e2035df957 added unit test for issue #76 2015-05-30 16:47:21 +02:00
Niels 58d7342be7 Merge pull request #73 from maqnouch/patch-1
Fix typos
2015-05-12 17:29:50 +02:00
AQNOUCH Mohammed 7da56cf292 Fix typos 2015-05-12 14:59:44 +01:00
Niels 61f0376366 more cleanup 2015-05-10 17:30:41 +02:00
Niels cb2102a2d2 some pretty-printing 2015-05-10 17:12:36 +02:00
Niels 072dc25521 Merge pull request #72 from aburgh/null-callback
Replace `default_callback` function with `nullptr` and check for null…
2015-05-10 17:10:47 +02:00
Niels 43ededf41f more cleanup 2015-05-10 17:03:50 +02:00
Aaron Burghardt ef54ace4d2 Replace default_callback function with nullptr and check for null callback function before calling it. This is cleaner and better performing. 2015-05-10 10:32:49 -04:00
Niels 76d3433e6c moved some code to json_value union 2015-05-10 16:30:33 +02:00
Niels 5ed80d308d some parsing performance improvements 2015-05-09 22:49:21 +02:00
Niels abb8653115 more test cases 2015-05-09 16:58:06 +02:00
Niels 03634cacbc cleanup 2015-05-09 15:38:58 +02:00
Niels 165d367493 updated README 2015-05-09 15:30:17 +02:00
Niels 9cdd278f45 overworked code for pull request #71 2015-05-09 15:29:20 +02:00
Niels aca3f65bbe Merge pull request #71 from likebeta/master
support enum
2015-05-09 15:23:51 +02:00
Niels 2b4e461702 fixed string definition 2015-05-09 15:09:52 +02:00
Niels 1f381d496d overworked coverage 2015-05-09 14:54:33 +02:00
Niels bb142d6cae added test cases 2015-05-09 14:37:22 +02:00
Niels 869035a6c9 added compliance test cases 2015-05-09 13:56:51 +02:00
易思龙 91aee10579 support enum
construct enum type to basic_json (proxy by int type)
```
    enum { t = 0 };
    json  j = json::array();
    j.push_back(t);

    j.push_back(json::object({
         {"game_type", t}
    }));
```
2015-05-09 17:44:10 +08:00
Niels 9f9d293bad valgrind still makes problems 2015-05-06 21:32:41 +02:00
Niels b67b13c29e Appveyor 2015-05-06 20:48:20 +02:00
Niels bef256600c added test cases 2015-05-06 20:46:04 +02:00
Niels 2cfc93fc76 overflows are handled wrong by Valgrind 2015-05-06 20:21:06 +02:00
Niels a8e92a6bfb fixed #68 2015-05-06 20:18:16 +02:00
Niels 17609f244d fixed #70 2015-05-06 19:52:12 +02:00
Niels 1580eee4ed applied #69 to header 2015-05-04 23:31:34 +02:00
Niels 723155a30a Merge pull request #69 from aburgh/callback_performance
Fix performance regression introduced with the parsing callback feature.
2015-05-04 15:39:44 +02:00
Aaron Burghardt ea3e922a12 Fix performance regression introduced with the parsing callback feature. 2015-05-04 09:08:55 -04:00
Niels 2b825760b5 removed failing test case 2015-05-03 21:37:14 +02:00
Niels 07dd3af848 another try 2015-05-03 21:28:57 +02:00
Niels 370929ac08 overworked test case 2015-05-03 21:10:22 +02:00
Niels c458bf18e6 more test cases 2015-05-03 20:59:11 +02:00
Niels 106705ed73 more tests 2015-05-03 20:42:24 +02:00
Niels 10bbb77491 test case for filter function 2015-05-03 20:18:16 +02:00
Niels 1143094e4c testing the callback function 2015-05-03 20:07:31 +02:00
Niels 093b97efc4 more tests 2015-05-03 19:55:45 +02:00
Niels f66e603686 more test cases 2015-05-03 18:59:58 +02:00
Niels 1ac4d673b6 fixed test case 2015-05-03 18:46:26 +02:00
Niels ab1ff9de53 added more test cases 2015-05-03 18:27:43 +02:00
Niels 84561d8866 improved test case coverage 2015-05-03 18:19:12 +02:00
Niels 952cbbc795 manually merged pull request #41 2015-05-03 17:52:13 +02:00
Niels faae8bb843 some typename fix 2015-04-27 23:09:51 +02:00
Niels 14e54b2b72 Appveyor 2015-04-27 22:53:46 +02:00
Niels ecc97bcf96 added /EHsc parameter 2015-04-27 22:45:21 +02:00
Niels 1068ad106b fixed Makefile 2015-04-27 22:35:45 +02:00
Niels e7da0b4b7c Appveyor 2015-04-26 23:56:42 +02:00
Niels 0c0a462c28 Appveyor 2015-04-26 23:47:11 +02:00
Niels 257bf46133 Appveyor 2015-04-26 23:41:11 +02:00
Niels c16ee07601 Appveyor 2015-04-26 23:31:22 +02:00
Niels 35485c05e3 Appveyor 2015-04-26 23:21:16 +02:00
Niels f3447b2b80 Appveyor 2015-04-26 23:14:51 +02:00
Niels 4a3c0edb75 Appveyor 2015-04-26 23:09:10 +02:00
Niels 4c7fbd7647 Appveyor 2015-04-26 23:03:15 +02:00
Niels 711e465f4a Appveyor test 2015-04-26 22:53:17 +02:00
Niels 1e20bfa14a another try 2015-04-26 22:47:40 +02:00
Niels ae2676e7f0 fixed Makefile 2015-04-26 22:25:38 +02:00
Niels 5e0d4d3830 does not 2015-04-26 22:09:15 +02:00
Niels a3ca1ae217 trying appveyor again 2015-04-26 22:00:20 +02:00
Niels 81d3973151 undid changes that broke the build 2015-04-26 21:51:35 +02:00
Niels f874b5f0f8 clean up
- removed m_final member
- parse_internal now takes a reference to a basic_json object to fill
with data
- header is automatically regenerated if re2c file is changed
2015-04-26 21:43:47 +02:00
Niels f09df96742 updated README 2015-04-26 15:16:07 +02:00
Niels 7a32bd22e9 Merge pull request #63 from Florianjw/master
Improve the implementations of the comparission-operators
2015-04-26 15:10:32 +02:00
Niels c7f95cc636 minor change to the parsing of objects/arrays 2015-04-26 15:10:04 +02:00
Florian Weber 4fbff7d140 simplify value_t::operator< by using a lookup-table 2015-04-26 14:55:06 +02:00
Florian Weber f5e95522aa remove braces around single-return-statement switch-cases 2015-04-26 14:44:56 +02:00
Florian Weber d2771eb1bb Fix comparission between integers and floats
Until now it depended on the parameter-order whether
integers and floats were compared as integers or floats.

Appart from being not logical, this might even have meant that
the provided “order” was in fact not that. (not sure here, but I
like to be carefull)
2015-04-26 14:39:39 +02:00
Florian Weber 306695dd25 fix typos and improve operator== 2015-04-26 14:31:31 +02:00
Florian Weber 28f64c22a9 simplify operator< 2015-04-26 14:19:56 +02:00
Niels a372937424 fixed some small issues 2015-04-26 13:37:01 +02:00
Niels e3ab0bc74a addressing issue #62 2015-04-25 23:10:23 +02:00
Niels 89a8491914 minor changes 2015-04-25 01:25:42 +02:00
Niels fc58a73523 fix #60 (double escaping) 2015-04-24 22:06:57 +02:00
Niels 28f21c43f4 updated README to recent pull request 2015-04-15 17:52:25 +02:00
Niels 3eb1b2a756 Merge pull request #59 from dkopecek/master
Fix compilation of json_unit with GCC 5
2015-04-15 08:53:40 +02:00
Daniel Kopecek ad6ad4ae1e Fix compilation of json_unit with GCC 5
Addressing:
```
+ make json_unit
g++ -std=c++11  -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wfloat-equal  -I src -I test -Dprivate=public test/unit.cpp  -o json_unit
In file included from test/catch.hpp:65:0,
                 from test/unit.cpp:11:
/usr/include/c++/5.0.0/sstream:300:7: error: 'struct std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>::__xfer_bufptrs' redeclared with different access
       struct __xfer_bufptrs
```
2015-04-14 16:02:49 +02:00
Niels 4c55ada0f7 another test case 2015-04-12 18:33:38 +02:00
Niels 6ddb115072 more coverage 2015-04-12 18:12:29 +02:00
Niels 2dd94dd943 some simplifications 2015-04-12 17:26:54 +02:00
Niels f03c6ce458 added missing test cases 2015-04-12 16:57:51 +02:00
Niels dda8a5c473 adjusted code to documentation; some cleanup 2015-04-12 16:19:21 +02:00
Niels 139ef0e750 implemented front() and back() 2015-04-12 14:14:00 +02:00
Niels ade49f8b2a constructor for an integer range 2015-04-12 13:15:26 +02:00
Niels b801adca76 started to implement sequence container 2015-04-12 12:02:30 +02:00
Niels 02f617f083 adjusted code to documentation 2015-04-11 19:26:12 +02:00
Niels a3210ee2a9 increase test coverage 2015-04-11 15:42:54 +02:00
Niels 6dceab583c implemented issue #57: erase with iterators 2015-04-11 15:30:19 +02:00
Niels d7d0509161 added a note about supported compilers to close #50 2015-04-09 19:21:24 +02:00
Niels 84195daf28 added erase function for arrays 2015-04-09 18:55:57 +02:00
Niels 9ea3dd9b60 another test case 2015-04-08 23:16:35 +02:00
Niels 9e8e11339d improved test case coverage 2015-04-08 22:58:35 +02:00
Niels 1bdb6acb1f overworked type conversion 2015-04-08 22:23:40 +02:00
Niels 0a96116b0c more SFINAE 2015-04-03 16:34:39 +02:00
Niels ea1046110d using "key_type" where possible 2015-04-03 14:43:44 +02:00
Niels b747881466 subtle fix for get() function 2015-04-03 14:20:15 +02:00
Niels 7db167afd1 documented empty() 2015-04-01 23:23:36 +02:00
Niels 9767523924 don't need this 2015-03-31 23:10:34 +02:00
Niels babaa11c99 Bower spec 2015-03-31 22:56:33 +02:00
Niels 3eb50dde30 added RTD badge 2015-03-31 22:41:51 +02:00
Niels e0027a8550 cleanup docs 2015-03-31 22:40:21 +02:00
Niels f9c4b02092 rename to check something with RTD 2015-03-31 22:39:16 +02:00
Niels 71fa44a6af started documentation with RTD 2015-03-31 22:24:28 +02:00
Niels c9379b68dd fix #52 (documented new functions) 2015-03-27 17:11:08 +01:00
Niels 5e89cb0acb implemented key()/value() for reverse iterators 2015-03-26 17:06:33 +01:00
Niels 47ea1c10d4 key/value function for iterators (#46)
Currently only support iterator and const_iterator. reverse_iterator
and const_reverse_iterator to be implemented soon.
2015-03-24 19:08:03 +01:00
Niels 8fc4061187 fixed acknowledgements 2015-03-24 19:06:40 +01:00
Niels 0707030bc5 minor changes to pull request #40 2015-03-24 18:05:58 +01:00
Niels 50e06a7bd1 Merge pull request #40 from aburgh/incremental
Parse streams incrementally.
2015-03-24 17:57:40 +01:00
Niels e3188897f8 more on #48: allowing non-std begin/end functions 2015-03-24 17:39:00 +01:00
Niels 6fc52f3302 fixed #47 (added erase function to remove key form object) 2015-03-24 16:50:55 +01:00
Niels 43417c350b fixed #42 (removed equality comparisons for floats) 2015-03-23 23:03:48 +01:00
Niels 8e1c5f2221 updated README 2015-03-23 20:30:51 +01:00
Niels 53e3da8071 minor adjustments to pull request #38 2015-03-23 20:27:30 +01:00
Niels a382a93a8e Merge pull request #38 from wtsi-hgi/feature/small-float-serialization
Feature/small float serialization
2015-03-23 20:15:50 +01:00
Niels bb2671df11 fixed #43 (adding friendship to allow iterator change) 2015-03-22 19:18:21 +01:00
Niels f2957dc3bf fixed #45 (added count function for keys in objects) 2015-03-22 19:07:43 +01:00
Niels cf829ac2e8 fixed deprecated warnings in issue #42 2015-03-22 17:50:43 +01:00
Niels abc6137001 fixed #48 (using nonmember begin/end) 2015-03-22 17:30:48 +01:00
Aaron Burghardt 396f64a058 Replaced leading tabs with spaces (4 per tab). 2015-03-02 15:25:09 -05:00
Aaron Burghardt 87746280ca Added parse() for streams. 2015-03-01 06:31:33 -05:00
Aaron Burghardt 2855c70c27 Use inplace configuration for yyfill and disable the parameter to yyfill. 2015-03-01 05:55:40 -05:00
Aaron Burghardt 268fd444e6 Added comments to new method yyfill. 2015-03-01 05:55:40 -05:00
Aaron Burghardt edb697293b Fixed variable adjustments in yyfill(). 2015-03-01 05:55:40 -05:00
Aaron Burghardt ec6979bf76 Purged old commented-out code. 2015-03-01 05:55:40 -05:00
Aaron Burghardt b66c306d47 Removed unused member m_state. 2015-03-01 05:55:40 -05:00
Aaron Burghardt 0d79e7c2a2 Removed duplicate m_marker updates in YYFILL macro. 2015-03-01 05:55:40 -05:00
Aaron Burghardt e3e18d7b85 Deleted extraneous comment. 2015-03-01 05:55:40 -05:00
Aaron Burghardt e4cc42cf81 Moved m_marker in lexer::scan() to be a member of lexer. 2015-03-01 05:55:40 -05:00
Aaron Burghardt 754c38e871 Moved buffer management into the lexer class and implemented YYFILL so that streams are read incrementally. 2015-03-01 05:55:40 -05:00
Joshua C. Randall 7bfcbe2825 Fixes serialization of small floats
Now uses std::snprintf() to generate a "%.15g" formatted string
for JSON values of type number_float. 15 decimals digits are
enough to round-trip an IEEE 754 double from string->double->string
and get an identical result.

std::snprintf is called twice. Once to determine the required
buffer size and then again after allocating a buffer of that
size.

Note that the buffer size *could* be hardcoded for better
performance. "%.15g" should result in strings of maximum length
23, plus one character for the terminating null for a buffer size
of 24.
2015-02-28 17:11:46 +00:00
Joshua C. Randall ef3ad895ae Adds (failing) test for small float serialisation 2015-02-28 15:53:48 +00:00
Niels 5526de1385 small syntax fix 2015-02-25 22:21:05 +01:00
Niels 63c70fa07e minor changes 2015-02-24 23:19:19 +01:00
Niels ec42245951 small change to GIF 2015-02-22 22:24:47 +01:00
Niels c9b5357227 increased delays in GIF 2015-02-22 18:09:22 +01:00
Niels 93b585afa4 added GIF 2015-02-22 17:55:25 +01:00
Niels d524e23204 overworked iterators 2015-02-22 17:52:27 +01:00
Niels bc2e3a798d a more forgiving array behavior 2015-02-21 13:24:07 +01:00
Niels 1cd256a95e minor syntax error in README 2015-02-19 00:06:15 +01:00
Niels 118ec996fd Merge pull request #36 from nlohmann/template
template version with re2c scanner
2015-02-19 00:04:28 +01:00
Niels c8c49dae5d fixed coverage 2015-02-18 22:43:25 +01:00
Niels afd02eee44 fixed [] operator; added README 2015-02-18 22:28:56 +01:00
Niels ca981270a0 added another test case 2015-02-17 00:36:29 +01:00
Niels 9e7941b6ba more type adjustments 2015-02-17 00:22:12 +01:00
Niels e2dff46d14 further type adjustments 2015-02-16 23:34:37 +01:00
Niels 432a54e570 some type fixes 2015-02-16 23:17:28 +01:00
Niels a3f52a5a04 minor change to make code more portable 2015-02-16 22:54:07 +01:00
Niels 5ca84052a7 removed unused code and fixed includes 2015-02-16 22:47:30 +01:00
Niels db91140156 clean up 2015-02-15 23:27:35 +01:00
Niels 429d2099ab more allocators 2015-02-15 23:13:46 +01:00
Niels b387761e12 forgot to destroy object 2015-02-15 22:58:35 +01:00
Niels 568d75954e experiment with user-defined allocator 2015-02-15 22:49:26 +01:00
Niels b1be1b45ee minor change 2015-02-15 18:43:17 +01:00
Niels d31d1ca664 fix of the fix 2015-02-15 17:40:46 +01:00
Niels 9f87fd464a fixed Valgrind error 2015-02-15 17:07:19 +01:00
Niels f1f72403cd some unicode magic 2015-02-15 16:56:54 +01:00
Niels 3e885c8328 added missing test case 2015-02-15 15:51:11 +01:00
Niels af568b9b27 test cases for new features 2015-02-15 15:45:00 +01:00
Niels b80ca376f9 added some missing features from 2.0 version 2015-02-15 15:16:11 +01:00
Niels 2d8b362849 further cleanup 2015-02-15 14:52:00 +01:00
Niels 2fc82358ce clean up 2015-02-15 13:35:51 +01:00
Niels b21bf95620 fixed test case coverage 2015-02-15 11:53:24 +01:00
Niels bb558d8e6f added Unicode support 2015-02-15 11:44:49 +01:00
Niels 6ef3cb51a4 some reorganization 2015-02-14 17:34:06 +01:00
Niels cc4a8319a1 reverse iterators 2015-02-14 16:47:14 +01:00
Niels d87e770767 forgot Makefile 2015-02-13 22:12:27 +01:00
Niels 005a5c2858 some fixes and cleanup 2015-02-13 21:46:33 +01:00
Niels 36e36bf84a two more test cases for numbers 2015-02-13 20:27:27 +01:00
Niels 3391e69248 six more test cases for numbers 2015-02-13 20:16:53 +01:00
Niels e346011876 more test cases for numbers 2015-02-13 20:02:36 +01:00
Niels c864ea2199 systematic test case for \uxxxx sequences 2015-02-13 18:57:28 +01:00
Niels 334b7f24ea more systematic test cases 2015-02-13 18:18:58 +01:00
Niels 40a0773e43 more test cases 2015-02-13 17:42:14 +01:00
Niels 4361c4d03f more test cases 2015-02-12 22:54:42 +01:00
Niels 583d20a3b1 more test cases 2015-02-11 22:42:49 +01:00
Niels 89a1b0247b fixed a major bug in the parser 2015-02-11 17:24:14 +01:00
Niels 3f8dc632e2 test cases for iterator classes 2015-02-11 15:29:41 +01:00
Niels 53c9564c51 bug fix and test cases 2015-02-11 14:58:52 +01:00
Niels 4d23c49601 another test case 2015-02-11 13:25:04 +01:00
Niels 7b7a54aca5 fixed a bug 2015-02-11 13:15:22 +01:00
Niels 032bcf6493 more test cases (unexpected ends) 2015-02-11 12:53:47 +01:00
Niels 1d177f82bd more test cases (0e1) 2015-02-11 12:36:30 +01:00
Niels cb96e30f25 try to understand re2c 2015-02-11 12:21:46 +01:00
Niels c1bf002522 more test cases (objects, floats) 2015-02-11 11:57:36 +01:00
Niels 3f46fe7a08 more test cases 2015-02-11 11:47:00 +01:00
Niels f1bd206994 number test cases 2015-02-11 11:36:45 +01:00
Niels 463c38df60 fix test case 2015-02-11 10:57:17 +01:00
Niels 4b9bd96ab1 re-added old (failing) test cases 2015-02-11 10:27:41 +01:00
Niels c816fd12a0 cleanup 2015-02-11 10:16:43 +01:00
Niels d609790fff added whitespace handling 2015-02-11 09:51:24 +01:00
Niels 5d280143b7 fixes 2015-02-11 09:41:23 +01:00
Niels 8a4e127a57 + moved lexer to class 2015-02-11 09:10:28 +01:00
Niels e845cd1db8 still errors... 2015-02-10 23:55:44 +01:00
Niels a201bc981d more test cases 2015-02-10 23:45:18 +01:00
Niels f6f7fcc88c another test case 2015-02-10 23:28:25 +01:00
Niels 0433e71fc3 rename member variables; add whitespace tests 2015-02-10 23:20:30 +01:00
Niels f9797f8eb2 try 2015-02-10 23:05:45 +01:00
Niels 1aebb6e6ed removing failing (?) test cases 2015-02-10 22:48:16 +01:00
Niels 6232c78f88 possible fix 2015-02-10 22:37:07 +01:00
Niels 1bbde4597b more test cases 2015-02-10 22:09:21 +01:00
Niels cd89a88b4a fix build error 2015-02-10 21:03:32 +01:00
Niels 963ec13b4a testing the parser 2015-02-10 20:52:39 +01:00
Niels 3589837071 more test cases 2015-02-10 20:28:16 +01:00
Niels 8c6bb04d10 added width feature / more test cases 2015-02-10 19:50:26 +01:00
Niels 4cd341d4db more unit tests 2015-02-10 18:51:09 +01:00
Niels 29a8d43d5a fixed tests for copy assignment 2015-02-10 17:40:47 +01:00
Niels d760ff5142 tests for comparison operators 2015-02-10 17:10:39 +01:00
Niels 2ec0c79e0f test cases and clean up 2015-02-09 21:10:19 +01:00
Niels 0cfd0f5d68 added test cases and fixed some warnings 2015-02-09 20:21:26 +01:00
Niels 0df642ded0 more test cases 2015-02-09 19:49:09 +01:00
Niels e53e84e1cc more test cases 2015-02-09 18:45:32 +01:00
Niels 48392cfa79 some bug fixing 2015-02-09 18:02:31 +01:00
Niels fe64ed5f01 another fix for travis 2015-02-08 19:22:48 +01:00
Niels 330ffd952b removed reverse_iterators and fixed some bugs 2015-02-08 19:18:39 +01:00
Niels 4c59ccd1d5 a fix for Travis 2015-02-08 18:38:24 +01:00
Niels 5b4dcfd8a4 more test cases 2015-02-08 18:27:16 +01:00
Niels 4a0ce18034 more test cases 2015-02-08 18:06:16 +01:00
Niels 27eab94ea1 more test cases 2015-02-08 17:45:56 +01:00
Niels a35d93e980 try with GCC 4.9 2015-02-08 16:57:53 +01:00
Niels d6f54711f3 hello coveralls... 2015-02-08 16:44:27 +01:00
Niels 572232614d more test cases 2015-02-08 16:37:21 +01:00
Niels 323764a8c5 more test cases 2015-02-08 16:24:38 +01:00
Niels d38596793e more test cases 2015-02-08 16:14:49 +01:00
Niels 441a6f267f more test cases 2015-02-08 16:08:48 +01:00
Niels 8ed9eaa629 more test cases 2015-02-08 15:57:24 +01:00
Niels 16b91d491e more test cases 2015-02-08 15:47:40 +01:00
Niels d0df796a10 more test cases 2015-02-08 14:54:16 +01:00
Niels 7cd9067ea2 more test cases 2015-02-08 14:38:52 +01:00
Niels 43ec6477bd more test cases 2015-02-08 14:10:36 +01:00
Niels f442b0d72c more test cases 2015-02-08 13:52:11 +01:00
Niels 5877bb9745 systematic unit tests 2015-02-08 13:25:09 +01:00
Niels caf82be2c7 added reverse iterators 2015-02-08 12:53:10 +01:00
Niels 87c250d843 another commit to trigger coverage 2015-02-07 19:14:23 +01:00
Niels cc274f8145 small changes with default values 2015-02-07 19:04:08 +01:00
Niels c1c3e72c96 include main source file for coveralls 2015-02-07 16:03:40 +01:00
Niels cf498ca4f2 added more features from master branch 2015-02-07 15:57:47 +01:00
Niels ac274dee2a Zwischenstand 2015-02-05 22:45:33 +01:00
Niels 16fa85e9f2 Zwischenstand 2015-02-05 22:45:21 +01:00
Niels a5188b08df strings are escaped 2015-02-04 22:49:46 +01:00
Niels 5ec433604a more test cases 2015-01-31 21:25:38 +01:00
Niels 385865c4ec remove checks in iterator 2015-01-31 20:46:23 +01:00
Niels 9dff05d9e3 exclude more files from coveralls 2015-01-31 20:31:43 +01:00
Niels d8f58b25fb coveralls adjustment 2015-01-31 20:26:47 +01:00
Niels 087010032d adjustments to coverall 2015-01-31 20:19:36 +01:00
Niels befd90dead cleanup 2015-01-31 20:13:11 +01:00
Niels c4d74856bb Merge pull request #33 from luxe/patch-1
more descriptive documentation in example
2015-01-26 07:51:40 +01:00
Trevor Hickey 20d75a26a5 more descriptive documentation in example
I wasn't sure what that parameter was at first glance
2015-01-25 21:00:28 -05:00
Niels b453cdb7a2 more examples 2015-01-24 21:11:42 +01:00
Niels 85aa0a328e updated README 2015-01-24 21:06:05 +01:00
Niels 5199382c91 worked on issue #8 and #27 2015-01-24 20:33:06 +01:00
Niels 47e3a3ed24 another test case 2015-01-23 20:46:46 +01:00
Niels f8d263a811 another test case 2015-01-23 18:42:24 +01:00
Niels 807de40463 implemented missing operator[] 2015-01-23 18:27:58 +01:00
Niels 36f14d21da more test cases for reverse iterators 2015-01-23 18:07:31 +01:00
Niels c22ee3f296 fixed an issue with non portability 2015-01-21 18:04:12 +01:00
Niels 6ee46ed519 cleanup 2015-01-21 17:42:45 +01:00
Niels d66743b9c2 fixed a memory leak 2015-01-21 15:59:52 +01:00
Niels bbc45eb4d8 overworked iterators 2015-01-21 15:43:24 +01:00
Niels 76be1ae1f6 + more adjustments toward a real container 2015-01-21 11:47:03 +01:00
Niels 3c780f0f57 + generic constructors for arrays and objects 2015-01-21 09:40:46 +01:00
Niels 7afabc2b7e another test case 2015-01-20 22:06:45 +01:00
Niels ee45bca4a9 + more test cases 2015-01-20 21:49:21 +01:00
Niels 75ba6ae4ff + improved test case coverage 2015-01-20 21:35:08 +01:00
Niels a7a946bd18 added missing header 2015-01-20 21:15:14 +01:00
Niels 54fc97d434 + set number type to int64_t
+ replaced several functions by template magic
2015-01-20 20:43:54 +01:00
Niels a144800774 + implemented member and non-member swap 2015-01-19 19:51:07 +01:00
Niels 7724d34741 fixed #31: only use spaces in pretty print 2015-01-18 10:58:48 +01:00
Niels b30e9ee5f4 test cases to cover 100% of the fix of #28 2015-01-13 19:26:42 +01:00
Niels 19043d2003 this should fix #28 2015-01-13 19:07:53 +01:00
Niels d47b0e749b updated README 2015-01-12 23:38:55 +01:00
Niels dcf71748a6 Merge pull request #26 from wancw/fix_clang_string_casting
Fix string conversion under Clang
2015-01-12 22:54:39 +01:00
WanCW 36f6199898 Fix string conversion under Clang 2015-01-12 20:03:41 +08:00
Niels bd05c7a18a small tidy up after pull request #22
- removed IDE leftovers
- adjusted const’ness of some functions
- style guide
2015-01-11 15:16:14 +01:00
Niels 6533b33387 Merge pull request #22 from Teemperor/unicode_escaping
Unicode escaping
2015-01-11 15:08:13 +01:00
Niels 8d9c2bea4e + applied style guide 2015-01-11 15:05:04 +01:00
Niels 80b5db16b5 Merge pull request #24 from Teemperor/fix_string_dumping
Fixed dumping of strings
2015-01-11 14:03:53 +01:00
Niels cc7e942870 Merge pull request #23 from Teemperor/gcc_remark_readme
Added a remark to the readme that coverage is GCC only for now
2015-01-11 12:47:00 +01:00
Raphael Isemann 7b97ec884e Fixed dumping of strings 2015-01-10 22:04:57 +01:00
Raphael Isemann a866a9d980 Reapplied code style fixes 2015-01-10 19:53:13 +01:00
Raphael Isemann a409ba9488 Fixed build 2015-01-10 18:46:01 +01:00
Raphael Isemann 0fcc414995 More testing and updated CMake to allow calling private functions from the tests 2015-01-10 18:28:53 +01:00
Raphael Isemann 85888e8205 Added a remark to the readme that coverage is GCC only for now 2015-01-10 18:09:46 +01:00
Raphael Isemann 6105ce5484 Allowed automerge 2015-01-10 17:33:18 +01:00
Raphael Isemann 1287f03084 Code point are two words, and so the "P" should be capital 2015-01-10 16:50:39 +01:00
Raphael Isemann 5a54e46709 Fully implemented the JSON spec 2015-01-10 16:49:10 +01:00
Raphael Isemann 222aacc213 Quick and dirty implementation for basic multilingual plane in the unicode escape mechanism 2015-01-10 10:36:30 +01:00
Niels 0cd2ecf48f minor style adjustments 2015-01-09 20:48:16 +01:00
Niels 3fa2e900ef + added Thanks section to README 2015-01-09 20:48:06 +01:00
Niels 69195e070f Merge pull request #21 from Teemperor/fixed_escaped_chars
Implemented the JSON spec for string parsing for everything but the \uXXXX escaping - see issue #12.
2015-01-09 20:32:08 +01:00
Raphael Isemann 13efc7a02a More tests to get line coverage backt o 100% 2015-01-09 20:24:58 +01:00
Raphael Isemann 7f4fcc51f6 Implemented the JSON spec for string parsing for everything but the \uXXXX escaping for unicode 2015-01-09 20:03:18 +01:00
Niels 52f399d55f created a header-only version (see issue #16) 2015-01-09 18:16:27 +01:00
Niels 2443aa6521 updated README 2015-01-09 17:50:50 +01:00
Niels 33f5236687 added missing header 2015-01-09 17:40:14 +01:00
Niels 535aef5ad0 Merge pull request #19 from kirkshoop/stditerator
add the std iterator typedefs to iterator and const_iterator
2015-01-09 17:37:42 +01:00
Niels 33f5e74905 minor syntax adjustments 2015-01-09 16:38:34 +01:00
Kirk Shoop 3486a5d9bb add the std iterator typedefs to iterator and const_iterator 2015-01-09 07:33:57 -08:00
Niels 661a44d156 Merge pull request #18 from Teemperor/fix_quote_escaping
Fixed escaped quotes (issue #17)
2015-01-09 16:32:39 +01:00
Raphael Isemann 4a39bfb17e Fixed typo in comments 2015-01-09 11:57:39 +01:00
Raphael Isemann fa0ee9c927 Fixed escaped quotes 2015-01-08 22:35:48 +01:00
Niels 4647401030 fixed #15 2015-01-06 22:05:32 +01:00
Niels bd9f49efb9 implemented pretty printing (issue #13)
- to_string() method is now called dump()
- syntax borrowed from Python’s json.dumps()
2015-01-06 21:44:07 +01:00
Niels 08456b8ff0 minor changes 2015-01-06 19:14:03 +01:00
Niels d84f8ebb02 valgrind parameter is not understood in travis 2015-01-06 18:57:44 +01:00
Niels 43a85be471 travis now checks with valgrind 2015-01-06 18:52:14 +01:00
Niels 5f05d02c6a Merge pull request #14 from elliotgoodrich/master
Fix double delete on std::bad_alloc exception
2015-01-06 18:43:21 +01:00
Niels a53c878c81 moved class into "nlohmann" namespace
- fixed issue #9
- also removed std::mutex member variable
- also added “std::” prefix to size_t variables
2015-01-06 18:41:24 +01:00
Elliot Goodrich 0773f40a8e Fix double delete on std::bad_alloc exception
If the new operator throws in the json::find methods then result.oi_ is
deleted again in the destructor of json::iterator/json::const_iterator,
which is a double delete and undefined behaviour.
2015-01-06 09:12:55 +00:00
Niels 4f0afbbe64 added note from http://isocpp.org/blog/2015/01/json-for-modern-cpp 2015-01-05 22:25:44 +01:00
Niels f0582a8b60 ignore some CMake files 2015-01-05 20:36:31 +01:00
Niels bf768d96d9 minor Markdown error 2015-01-05 20:30:34 +01:00
Niels b39f78924a Merge pull request #6 from Teemperor/master
Added CMake and lcov
2015-01-05 20:28:56 +01:00
Raphael Isemann 67459fcd83 Added CMake to the README 2015-01-05 11:29:41 +01:00
Raphael Isemann bd4e0e4fee Merge branch 'master' of github.com:nlohmann/json 2015-01-05 11:20:32 +01:00
Raphael Isemann 0f371b4086 CMake and coverage report 2015-01-05 11:19:42 +01:00
Niels a9669a410d removed "noexpect" from all functions that use new 2015-01-04 23:18:24 +01:00
Niels 540cda6118 used _-suffix for member variables 2015-01-04 23:09:30 +01:00
Niels 3bef1a5097 renamed "toString()" to "to_string()" 2015-01-04 20:50:28 +01:00
Niels f63ff7727e renamed class from "JSON" to "son" 2015-01-04 20:43:25 +01:00
Niels 4d00105e5c tidy up 2015-01-04 19:05:46 +01:00
Niels 0019c85b85 fix 2015-01-04 18:55:15 +01:00
Niels aa166a4739 updated examples 2015-01-04 18:52:04 +01:00
Niels 77ea63ceb5 fixed a link 2015-01-04 18:32:03 +01:00
Niels 4ea98517f5 updated README 2015-01-04 13:20:32 +01:00
Niels bd0be5f0af fixed memory leak 2015-01-04 12:29:16 +01:00
Niels 481f377cfe + guard call to std::ios_base::sync_with_stdio 2015-01-04 12:05:28 +01:00
Niels 9537c70b67 removing flawed test case 2015-01-03 17:51:14 +01:00
Niels 764ed26c41 cleanup 2015-01-03 17:18:17 +01:00
Niels 18364aac85 parser returns an object 2015-01-02 17:19:40 +01:00
Niels 16c30cff8b removed old C fragments 2015-01-02 15:29:36 +01:00
Niels af4aca9edd + better string handling 2015-01-02 12:47:32 +01:00
Niels 85abe926cf fixed coveralls call to ignore benchmarks folder 2014-12-30 12:02:38 +01:00
Niels 6995d33fb1 + fixed documentation bugs 2014-12-30 11:57:58 +01:00
Niels 2335d3f3d5 tidy up 2014-12-30 11:47:28 +01:00
Niels 39cf26e2db minor changes 2014-12-30 11:29:59 +01:00
Niels 2be4f24837 + updated reference 2014-12-30 11:19:35 +01:00
Niels 9e61092fc6 + overworked parser 2014-12-30 10:54:01 +01:00
Niels 4e44390090 + fixed a bug in the stream input 2014-12-29 21:13:03 +01:00
Niels 15a9d3cff6 minor changes 2014-12-29 19:54:31 +01:00
Niels 0b8dda1e0c minor changes 2014-12-29 18:32:17 +01:00
Niels f50fdd08a7 syntax highlighting 2014-12-29 18:20:55 +01:00
Niels 6687ea1a36 updated reference 2014-12-29 18:19:06 +01:00
Niels cff4d40afd type reference 2014-12-29 17:07:00 +01:00
Niels a8c4f84fb8 + removed data() function 2014-12-29 16:45:54 +01:00
Niels 515d731fd4 + documentation 2014-12-29 13:35:52 +01:00
Niels 725202356b + fix memory issues 2014-12-29 12:51:20 +01:00
Niels 2c1b3e5108 + small cleanup 2014-12-29 00:02:14 +01:00
Niels 3985226f76 issue badge 2014-12-28 23:21:46 +01:00
Niels bed47db168 + that could be it! 2014-12-28 23:09:31 +01:00
Niels 776611c270 + another check 2014-12-28 22:59:11 +01:00
Niels 0ced78bfa8 + test 2014-12-28 22:51:27 +01:00
Niels b573841ace + more test cases 2014-12-28 22:38:57 +01:00
Niels 98af0887f2 + more test cases 2014-12-28 22:29:06 +01:00
Niels ea85da8a55 + more test cases 2014-12-28 22:16:58 +01:00
Niels aacb58e56b + more test cases 2014-12-28 22:07:10 +01:00
Niels 48a349a058 + more test cases 2014-12-28 21:53:13 +01:00
Niels 8f45d9351e + overworked switches 2014-12-28 20:07:56 +01:00
Niels 4810091bab + more test cases 2014-12-28 19:51:02 +01:00
Niels b2b5e4e7e1 + more test cases 2014-12-28 18:12:07 +01:00
Niels cd48a01b20 + more test 2014-12-28 18:00:50 +01:00
Niels d3216300b2 + more test cases 2014-12-28 17:26:33 +01:00
Niels ea94518a64 + more test cases 2014-12-28 17:09:38 +01:00
Niels 5b1f69ce5b + overworked comments 2014-12-28 16:48:22 +01:00
Niels 45b101d200 + more test cases 2014-12-28 15:57:43 +01:00
Niels 6561e4e424 + execute unit tests explicitly 2014-12-28 15:46:36 +01:00
Niels 75b2f4098d + more test cases 2014-12-28 15:41:33 +01:00
Niels a68b4cafa2 + more test cases 2014-12-28 14:57:21 +01:00
Niels 2e26faf91c + more test cases 2014-12-28 14:39:34 +01:00
Niels 88786c86bb more test cases 2014-12-28 13:40:19 +01:00
Niels ef5b589686 more test cases 2014-12-28 13:31:24 +01:00
Niels 215391983a + more test cases 2014-12-28 13:22:06 +01:00
Niels 1c10efb7be + error fix 2014-12-28 13:11:50 +01:00
Niels 0720323ed7 another test case 2014-12-28 13:09:38 +01:00
Niels 8d4f675151 + test cases for clear() 2014-12-28 12:50:52 +01:00
Niels b60fe6e7e2 - removed old test cases 2014-12-28 12:38:08 +01:00
Niels 23006bd57b exclude tests 2014-12-28 12:24:52 +01:00
Niels 87d24ca670 pass gcov version 2014-12-28 12:20:53 +01:00
Niels 08a60a7803 clang seems not to work 2014-12-28 11:27:38 +01:00
Niels 1cb6426ddc wrong package name 2014-12-28 11:24:40 +01:00
Niels 41ab5b1f59 + fixing coverall 2014-12-28 11:20:48 +01:00
Niels 822172c502 make pretty 2014-12-28 11:15:13 +01:00
Niels 9f562caa2c Merge pull request #5 from nlohmann/2.0
Version 2.0
2014-12-28 11:09:35 +01:00
Niels 30ac86a0fe + updated README 2014-12-28 11:06:01 +01:00
Niels db804169c7 added coverage badge 2014-12-28 09:29:33 +01:00
Niels b57179e0fe + fixed a compiler warning
+ added coveralls
2014-12-28 09:23:49 +01:00
Niels 36fcc942c4 using GCC 4.8 for Travis 2014-12-28 09:21:06 +01:00
Niels fbad7fac17 2.0 preview 2014-12-28 09:11:01 +01:00
Niels d1ac3d9938 benchmark 2013-12-11 13:23:50 +01:00
Niels 5dbdba3c43 towards a benchmark 2013-12-11 10:50:50 +01:00
Niels bbc0f64fa5 a Makefile target for test coverage 2013-12-11 10:23:31 +01:00
Niels d47a81296f fixed a typo 2013-12-11 08:49:07 +01:00
Niels 77fa133946 removed unused flags 2013-12-11 08:41:12 +01:00
Niels 278a9e7052 simplified code 2013-12-11 08:41:02 +01:00
Niels 442cc9b6de added debug output to test cases 2013-12-11 08:40:53 +01:00
Niels 81367a9a10 fixed a cppcheck warning 2013-12-10 12:44:23 +01:00
Niels Lohmann a8f62ca052 + a fix for C++98 2013-07-15 08:32:10 +02:00
Niels 9a567d9d2d - tidied code
- added more documentation
2013-07-11 14:19:11 +02:00
Niels 52c2cb8ce7 - removed pointers to POD inside the union 2013-07-10 14:57:51 +02:00
Niels 4e6a400a23 - reorganized payload 2013-07-10 14:33:17 +02:00
Niels ec6e628d4f - minor tweaks 2013-07-05 16:45:17 +02:00
Niels cb2da141ec - further adjustments 2013-07-05 16:15:29 +02:00
Niels 6abf140b2b - updated README 2013-07-05 14:57:03 +02:00
Niels d5c56f2771 - a README 2013-07-05 14:44:45 +02:00
Niels 0ee8d53a28 - a find() function 2013-07-05 14:16:47 +02:00
Niels ac5ff65856 - bugfixing 2013-07-05 12:32:23 +02:00
Niels abad903f31 - memory problem 2013-07-05 11:57:12 +02:00
Niels 61461ec456 - fixes from Harro 2013-07-05 11:23:49 +02:00
Niels 23ada516aa - header for NULL 2013-07-04 18:16:24 +02:00
Niels d035fa581d - added missing headers 2013-07-04 18:13:17 +02:00
Niels ff41ca8fd6 - removing Autoconf version requirement to allow travis to work 2013-07-04 17:13:04 +02:00
Niels 206e15dff7 - fixed bugs and added test cases 2013-07-04 17:06:53 +02:00
Niels ac6ced6fb8 - a config file for travis 2013-07-04 10:54:16 +02:00
Niels b9465f8d65 - ignore DS_Stores 2013-07-04 10:49:35 +02:00
Niels 4502e7e51c - initial commit 2013-07-04 10:49:03 +02:00
2494 changed files with 4255233 additions and 92429 deletions
-3
View File
@@ -1,3 +0,0 @@
# JSON for Modern C++
![](images/json.gif)
+24
View File
@@ -0,0 +1,24 @@
{
"targets": {
"xenial-i386": {
"buildenv": "xenial-i386",
"builddeps": ["build-essential", "cmake"],
"buildcmd": ["mkdir cm", "cd cm", "cmake ..", "cmake --build .", "ctest --output-on-failure"]
},
"xenial-amd64": {
"buildenv": "xenial-amd64",
"builddeps": ["build-essential", "cmake"],
"buildcmd": ["mkdir cm", "cd cm", "cmake ..", "cmake --build .", "ctest --output-on-failure"]
},
"fedora24-x86_64": {
"buildenv": "fedora24-x86_64",
"builddeps": ["cmake", "make", "clang"],
"buildcmd": ["mkdir cm", "cd cm", "CXX=clang++ cmake ..", "cmake --build .", "ctest --output-on-failure"]
},
"osx": {
"buildenv": "osx",
"builddeps": ["build-essential"],
"buildcmd": ["make check"]
}
}
}
+77
View File
@@ -0,0 +1,77 @@
[![Issue Stats](http://issuestats.com/github/nlohmann/json/badge/pr?style=flat)](http://issuestats.com/github/nlohmann/json) [![Issue Stats](http://issuestats.com/github/nlohmann/json/badge/issue?style=flat)](http://issuestats.com/github/nlohmann/json)
# How to contribute
This project started as a little excuse to exercise some of the cool new C++11 features. Over time, people actually started to use the JSON library (yey!) and started to help improve it by proposing features, finding bugs, or even fixing my mistakes. I am really [thankful](https://github.com/nlohmann/json/blob/master/README.md#thanks) for this and try to keep track of all the helpers.
To make it as easy as possible for you to contribute and for me to keep an overview, here are a few guidelines which should help us avoid all kinds of unnecessary work or disappointment. And of course, this document is subject to discussion, so please [create an issue](https://github.com/nlohmann/json/issues/new) or a pull request if you find a way to improve it!
## Private reports
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 publisheed), please send an email to <mail@nlohmann.me>.
## Prerequisites
Please [create an issue](https://github.com/nlohmann/json/issues/new), assuming one does not already exist, and describe your concern. Note you need a [GitHub account](https://github.com/signup/free) for this.
If you want propose changes to the code, you need to download the [`re2c`](http://re2c.org) tool.
## Describe your issue
Clearly describe the issue:
- If it is a bug, please describe how to **reproduce** it. If possible, attach a complete example which demonstrates the error. Please also state what you **expected** to happen instead of the error.
- If you propose a change or addition, try to give an **example** how the improved code could look like or how to use it.
- If you found a compilation error, please tell us which **compiler** (version and operating system) you used and paste the (relevant part of) the error messages to the ticket.
## Files to change
There are currently two files which need to be edited:
1. [`src/json.hpp.re2c`](https://github.com/nlohmann/json/blob/master/src/json.hpp.re2c) (note the `.re2c` suffix) - This file contains a comment section which describes the JSON lexic. This section is translated by [`re2c`](http://re2c.org) into file [`src/json.hpp`](https://github.com/nlohmann/json/blob/master/src/json.hpp) which is plain "vanilla" C++11 code. (In fact, the generated lexer consists of some hundred lines of `goto`s, which is a hint you never want to edit this file...).
If you only edit file `src/json.hpp` (without the `.re2c` suffix), your changes will be overwritten as soon as the lexer is touched again. To generate the `src/json.hpp` file which is actually used during compilation of the tests and all other code, please execute
```sh
make re2c
```
To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`. We currently use re2c version 0.16. Please also use this version, because other re2c versions tend to create code that differs a lot from which makes diffs unusable.
2. [`test/src/unit.cpp`](https://github.com/nlohmann/json/blob/master/test/unit.cpp) - This contains the [Catch](https://github.com/philsquared/Catch) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled and executed with
```sh
make check
```
The test cases are also executed with several different compilers on [Travis](https://travis-ci.org/nlohmann/json) once you open a pull request.
Please understand that I cannot accept pull requests changing only file `src/json.hpp`.
## Note
- If you open a pull request, the code will be automatically tested with [Valgrind](http://valgrind.org)'s Memcheck tool to detect memory leaks. Please be aware that the execution with Valgrind _may_ in rare cases yield different behavior than running the code directly. This can result in failing unit tests which run successfully without Valgrind.
- There is a Makefile target `make pretty` which runs [Artistic Style](http://astyle.sourceforge.net) to fix indentation. If possible, run it before opening the pull request. Otherwise, we shall run it afterward.
## Please don't
- Please do not only make changes to file `src/json.hpp` -- please read the paragraph above and understand why `src/json.hpp.re2c` exists.
- The C++11 support varies between different **compilers** and versions. Please note the [list of supported compilers](https://github.com/nlohmann/json/blob/master/README.md#supported-compilers). Some compilers like GCC 4.8 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with `#ifdef`s or other means.
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for these kind of bugs). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
- Please refrain from proposing changes that would **break [JSON](http://json.org) conformance**. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
- We shall not extend the library to **support comments**. There is quite some [controversy](https://www.reddit.com/r/programming/comments/4v6chu/why_json_doesnt_support_comments_douglas_crockford/) around this topic, and there were quite some [issues](https://github.com/nlohmann/json/issues/376) on this. We believe that JSON is fine without comments.
- We do not preserve the **insertion order of object elements**. The [JSON standard](https://tools.ietf.org/html/rfc7159.html) defines objects as "an unordered collection of zero or more name/value pairs". To this end, this library does not preserve insertion order of name/value pairs. (In fact, keys will be traversed in alphabetical order as `std::map` with `std::less` is used by default.) Note this behavior conforms to the standard, and we shall not it to any other order.
- Please do not open pull requests that address **multiple issues**.
## Wanted
The following areas really need contribution:
- Extending the **continuous integration** toward more exotic compilers such as Android NDK, Intel's Compiler, or the bleeding-edge versions of GCC or Clang.
- Improving the efficiency of the **JSON parser**. The current parser is implemented as a naive recursive descent parser with hand coded string handling. More sophisticated approaches like LALR parsers would be really appreciated. That said, parser generators like Bison or ANTLR do not play nice with single-header files -- I really would like to keep the parser inside the `json.hpp` header, and I am not aware of approaches similar to [`re2c`](http://re2c.org) for parsing.
- Extending and updating existing **benchmarks** to include (the most recent version of) this library. Though efficiency is not everything, speed and memory consumption are very important characteristics for C++ developers, so having proper comparisons would be interesting.
+46
View File
@@ -0,0 +1,46 @@
## Files to change
There are currently two files which need to be edited:
1. [`src/json.hpp.re2c`](https://github.com/nlohmann/json/blob/master/src/json.hpp.re2c) (note the `.re2c` suffix) - This file contains a comment section which describes the JSON lexic. This section is translated by [`re2c`](http://re2c.org) into file [`src/json.hpp`](https://github.com/nlohmann/json/blob/master/src/json.hpp) which is plain "vanilla" C++11 code. (In fact, the generated lexer consists of some hundred lines of `goto`s, which is a hint you never want to edit this file...).
If you only edit file `src/json.hpp` (without the `.re2c` suffix), your changes will be overwritten as soon as the lexer is touched again. To generate the `src/json.hpp` file which is actually used during compilation of the tests and all other code, please execute
```sh
make re2c
```
To run [`re2c`](http://re2c.org) and generate/overwrite file `src/json.hpp` with your changes in file `src/json.hpp.re2c`.
2. [`test/src/unit.cpp`](https://github.com/nlohmann/json/blob/master/test/unit.cpp) - This contains the [Catch](https://github.com/philsquared/Catch) unit tests which currently cover [100 %](https://coveralls.io/github/nlohmann/json) of the library's code.
If you add or change a feature, please also add a unit test to this file. The unit tests can be compiled with
```sh
make
```
and can be executed with
```sh
./json_unit
```
The test cases are also executed with several different compilers on [Travis](https://travis-ci.org/nlohmann/json) once you open a pull request.
Please understand that I cannot accept pull requests changing only file `src/json.hpp`.
## Note
- If you open a pull request, the code will be automatically tested with [Valgrind](http://valgrind.org)'s Memcheck tool to detect memory leaks. Please be aware that the execution with Valgrind _may_ in rare cases yield different behavior than running the code directly. This can result in failing unit tests which run successfully without Valgrind.
## Please don't
- Only make changes to file `src/json.hpp` -- please read the paragraph above and understand why `src/json.hpp.re2c` exists.
- The C++11 support varies between different **compilers** and versions. Please note the [list of supported compilers](https://github.com/nlohmann/json/blob/master/README.md#supported-compilers). Some compilers like GCC 4.8 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with `#ifdef`s or other means.
- Specifically, I am aware of compilation problems with **Microsoft Visual Studio** (there even is an [issue label](https://github.com/nlohmann/json/issues?utf8=✓&q=label%3A%22visual+studio%22+) for these kind of bugs). I understand that even in 2016, complete C++11 support isn't there yet. But please also understand that I do not want to drop features or uglify the code just to make Microsoft's sub-standard compiler happy. The past has shown that there are ways to express the functionality such that the code compiles with the most recent MSVC - unfortunately, this is not the main objective of the project.
- Please refrain from proposing changes that would **break [JSON](http://json.org) conformance**. If you propose a conformant extension of JSON to be supported by the library, please motivate this extension.
- Please do not open pull requests that address **multiple issues**.
+31
View File
@@ -0,0 +1,31 @@
json_unit
json_benchmarks
fuzz-testing
*.dSYM
*.o
*.gcno
*.gcda
working
doc/xml
doc/html
me.nlohmann.json.docset
benchmarks/files/numbers/*.json
.idea
cmake-build-debug
test/test-*
.svn
test/thirdparty/Fuzzer/libFuzzer.a
test/parse_afl_fuzzer
test/parse_cbor_fuzzer
test/parse_msgpack_fuzzer
+277
View File
@@ -0,0 +1,277 @@
#########################
# project configuration #
#########################
# C++ project
language: cpp
dist: trusty
sudo: required
###################
# global settings #
###################
env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "m89SSgE+ASLO38rSKx7MTXK3n5NkP9bIx95jwY71YEiuFzib30PDJ/DifKnXxBjvy/AkCGztErQRk/8ZCvq+4HXozU2knEGnL/RUitvlwbhzfh2D4lmS3BvWBGS3N3NewoPBrRmdcvnT0xjOGXxtZaJ3P74TkB9GBnlz/HmKORA="
################
# build matrix #
################
matrix:
include:
# Valgrind
- os: linux
compiler: gcc
env:
- COMPILER=g++-4.9
- SPECIAL=valgrind
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, valgrind]
after_success:
- make check TEST_PREFIX="valgrind --error-exitcode=1 --leak-check=full " TEST_PATTERN=""
# cLang sanitizer
# note: sadly clang's libc++ has errors when running with sanitize,
# so we use clang with gcc's libstdc++ which doesn't give those error.
# that's why we need to install g++-6 to get the lastest version
- os: linux
env:
- LLVM_VERSION=3.8.1
- SPECIAL=sanitizer
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-6
compiler: clang
before_script:
- make clang_sanitize
# cppcheck
- os: linux
compiler: gcc
env:
- COMPILER=g++-4.9
- SPECIAL=cppcheck
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, cppcheck]
after_success:
- make cppcheck
# no exceptions
- os: linux
compiler: gcc
env:
- COMPILER=g++-4.9
- SPECIAL=no_exceptions
- TEST_PATTERN=-e \"*\"
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, cppcheck]
before_script:
- CPPFLAGS="-DJSON_NOEXCEPTION" make
# Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/)
- os: linux
compiler: gcc
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.9', 'ruby']
before_script:
- wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz
- tar xf lcov_1.11.orig.tar.gz
- sudo make -C lcov-1.11/ install
- gem install coveralls-lcov
- pip install --user cpp-coveralls
after_success:
- make clean
- CXXFLAGS="--coverage -g -O0" CPPFLAGS="-DNDEBUG" make json_unit
- test/json_unit "*"
- coveralls --build-root test --exclude src/catch.hpp --exclude src/unit-algorithms.cpp --exclude src/unit-allocator.cpp --exclude src/unit-capacity.cpp --exclude src/unit-class_const_iterator.cpp --exclude src/unit-class_iterator.cpp --exclude src/unit-class_lexer.cpp --exclude src/unit-class_parser.cpp --exclude src/unit-comparison.cpp --exclude src/unit-concepts.cpp --exclude src/unit-constructor1.cpp --exclude src/unit-constructor2.cpp --exclude src/unit-convenience.cpp --exclude src/unit-conversions.cpp --exclude src/unit-deserialization.cpp --exclude src/unit-element_access1.cpp --exclude src/unit-element_access2.cpp --exclude src/unit-inspection.cpp --exclude src/unit-iterator_wrapper.cpp --exclude src/unit-iterators1.cpp --exclude src/unit-iterators2.cpp --exclude src/unit-json_patch.cpp --exclude src/unit-json_pointer.cpp --exclude src/unit-modifiers.cpp --exclude src/unit-pointer_access.cpp --exclude src/unit-readme.cpp --exclude src/unit-reference_access.cpp --exclude src/unit-regression.cpp --exclude src/unit-serialization.cpp --exclude src/unit-testsuites.cpp --exclude src/unit-unicode.cpp --include ../src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9'
- lcov --directory src --directory test/src --capture --output-file coverage.info --rc lcov_branch_coverage=1 --no-external
- lcov --remove coverage.info 'test/src/*' --output-file coverage.info --rc lcov_branch_coverage=1
- lcov --list coverage.info --rc lcov_branch_coverage=1
- coveralls-lcov --repo-token F9bs4Nop10JRgqPQXRcifyQKYhb3FczkS coverage.info
env:
- COMPILER=g++-4.9
- SPECIAL=coveralls
# Coverity (only for branch coverity_scan)
- os: linux
compiler: clang
before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
addons:
coverity_scan:
project:
name: "nlohmann/json"
description: "Build submitted via Travis CI"
notification_email: niels.lohmann@gmail.com
build_command_prepend: "make clean"
build_command: "make"
branch_pattern: coverity_scan
env:
- LLVM_VERSION=3.6.0
- SPECIAL=coverity
# OSX / Clang
- os: osx
osx_image: xcode6.4
- os: osx
osx_image: xcode7.3
- os: osx
osx_image: xcode8
- os: osx
osx_image: xcode8.1
- os: osx
osx_image: xcode8.2
# Linux / GCC
- os: linux
compiler: gcc
env: COMPILER=g++-4.9
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-4.9
- os: linux
compiler: gcc
env: COMPILER=g++-5
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-5
- os: linux
compiler: gcc
env: COMPILER=g++-6
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-6
# Linux / Clang
- os: linux
env: LLVM_VERSION=3.6.0
compiler: clang
- os: linux
env: LLVM_VERSION=3.6.1
compiler: clang
- os: linux
env: LLVM_VERSION=3.6.2
compiler: clang
- os: linux
env: LLVM_VERSION=3.7.0
compiler: clang
- os: linux
env: LLVM_VERSION=3.7.1
compiler: clang
- os: linux
env: LLVM_VERSION=3.8.0
compiler: clang
- os: linux
env: LLVM_VERSION=3.8.1
compiler: clang
#####################
# installation step #
#####################
# set directories to cache
cache:
directories:
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.2
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.1
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.0
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.0
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.1
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.0
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.1
install:
# create deps dir if not existing
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- mkdir -p ${DEPS_DIR}
# make sure CXX is correctly set
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi
# install LLVM/clang when LLVM_VERSION is set
- |
if [[ "${LLVM_VERSION}" != "" ]]; then
LLVM_DIR=${DEPS_DIR}/llvm-${LLVM_VERSION}
if [[ -z "$(ls -A ${LLVM_DIR})" ]]; then
travis_retry wget --quiet https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz
tar xfz cmake-3.6.1.tar.gz
(cd cmake-3.6.1 && ./configure --prefix=${LLVM_DIR}/cmake && make install)
export PATH="${LLVM_DIR}/cmake/bin:${PATH}"
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz"
CLANG_URL="http://llvm.org/releases/${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04.tar.xz"
mkdir -p ${LLVM_DIR} ${LLVM_DIR}/build ${LLVM_DIR}/projects/libcxx ${LLVM_DIR}/projects/libcxxabi ${LLVM_DIR}/clang
travis_retry wget --quiet -O - ${LLVM_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}
travis_retry wget --quiet -O - ${LIBCXX_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/projects/libcxx
travis_retry wget --quiet -O - ${LIBCXXABI_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/projects/libcxxabi
travis_retry wget --quiet -O - ${CLANG_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/clang
(cd ${LLVM_DIR}/build && cmake .. -DCMAKE_INSTALL_PREFIX=${LLVM_DIR}/install -DCMAKE_CXX_COMPILER=clang++)
(cd ${LLVM_DIR}/build/projects/libcxx && make install -j2)
(cd ${LLVM_DIR}/build/projects/libcxxabi && make install -j2)
fi
export CXXFLAGS="-nostdinc++ -isystem ${LLVM_DIR}/install/include/c++/v1"
export LDFLAGS="-L ${LLVM_DIR}/install/lib -l c++ -l c++abi"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LLVM_DIR}/install/lib"
export PATH="${LLVM_DIR}/clang/bin:${PATH}"
fi
################
# build script #
################
script:
# show OS/compiler version
- uname -a
- $CXX --version
# compile and execute unit tests
- make check
# check if homebrew works (only checks develop branch)
- if [ `which brew` ]; then
brew update ;
brew tap nlohmann/json ;
brew install nlohmann_json --HEAD ;
brew test nlohmann_json ;
fi
-1
View File
File diff suppressed because one or more lines are too long
+55
View File
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.0)
# define the project
project(nlohmann_json VERSION 2.1.0 LANGUAGES CXX)
enable_testing()
option(BuildTests "Build the unit tests" ON)
# define project variables
set(JSON_TARGET_NAME ${PROJECT_NAME})
set(JSON_PACKAGE_NAME ${JSON_TARGET_NAME})
set(JSON_TARGETS_FILENAME "${JSON_PACKAGE_NAME}Targets.cmake")
set(JSON_CONFIG_FILENAME "${JSON_PACKAGE_NAME}Config.cmake")
set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake")
set(JSON_CONFIG_DESTINATION "cmake")
set(JSON_INCLUDE_DESTINATION "include/nlohmann")
# create and configure the library target
add_library(${JSON_TARGET_NAME} INTERFACE)
target_include_directories(${JSON_TARGET_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${JSON_INCLUDE_DESTINATION}>)
# create and configure the unit test target
if (BuildTests)
add_subdirectory(test)
endif()
# generate a config and config version file for the package
include(CMakePackageConfigHelpers)
configure_package_config_file("cmake/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION}
PATH_VARS JSON_INCLUDE_DESTINATION)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
# export the library target and store build directory in package registry
export(TARGETS ${JSON_TARGET_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}")
export(PACKAGE ${JSON_PACKAGE_NAME})
# install library target and config files
install(TARGETS ${JSON_TARGET_NAME}
EXPORT ${JSON_PACKAGE_NAME})
install(FILES "src/json.hpp"
DESTINATION ${JSON_INCLUDE_DESTINATION})
install(EXPORT ${JSON_PACKAGE_NAME}
FILE ${JSON_TARGETS_FILENAME}
DESTINATION ${JSON_CONFIG_DESTINATION})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
"${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
DESTINATION ${JSON_CONFIG_DESTINATION})
+452
View File
@@ -0,0 +1,452 @@
# Change Log
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
## [v2.1.0](https://github.com/nlohmann/json/releases/tag/v2.1.0) (2017-01-28)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.10...v2.1.0)
- Parsing multiple JSON objects from a string or stream [\#438](https://github.com/nlohmann/json/issues/438)
- Use-of-uninitialized-value \(OSS-Fuzz issue 477\) [\#437](https://github.com/nlohmann/json/issues/437)
- add `reserve` function for array to reserve memory before adding json values into it [\#436](https://github.com/nlohmann/json/issues/436)
- Typo in examples page [\#434](https://github.com/nlohmann/json/issues/434)
- avoid malformed json [\#433](https://github.com/nlohmann/json/issues/433)
- How to add json objects to a map? [\#432](https://github.com/nlohmann/json/issues/432)
- create json instance from raw json \(unsigned char\*\) [\#431](https://github.com/nlohmann/json/issues/431)
- Getting std::invalid\_argument: stream error when following example [\#429](https://github.com/nlohmann/json/issues/429)
- Forward declare-only header? [\#427](https://github.com/nlohmann/json/issues/427)
- Implicit conversion from array to object [\#425](https://github.com/nlohmann/json/issues/425)
- Automatic ordered JSON [\#424](https://github.com/nlohmann/json/issues/424)
- error C4996: 'strerror' when reading file [\#422](https://github.com/nlohmann/json/issues/422)
- Get an error - JSON pointer must be empty or begin with '/' [\#421](https://github.com/nlohmann/json/issues/421)
- size parameter for parse\(\) [\#419](https://github.com/nlohmann/json/issues/419)
- json.hpp forcibly defines GCC\_VERSION [\#417](https://github.com/nlohmann/json/issues/417)
- Use-of-uninitialized-value \(OSS-Fuzz issue 377\) [\#416](https://github.com/nlohmann/json/issues/416)
- Single char converted to ASCII code instead of string [\#413](https://github.com/nlohmann/json/issues/413)
- How to know if a string was parsed as utf-8? [\#406](https://github.com/nlohmann/json/issues/406)
- Overloaded += to add objects to an array makes no sense? [\#404](https://github.com/nlohmann/json/issues/404)
- Finding a value in an array [\#399](https://github.com/nlohmann/json/issues/399)
- add release information in static function [\#397](https://github.com/nlohmann/json/issues/397)
- Optimize memory usage of json objects in combination with binary serialization [\#373](https://github.com/nlohmann/json/issues/373)
- Conversion operators not considered [\#369](https://github.com/nlohmann/json/issues/369)
- Append ".0" to serialized floating\_point values that are digits-only. [\#362](https://github.com/nlohmann/json/issues/362)
- Add a customization point for user-defined types [\#328](https://github.com/nlohmann/json/issues/328)
- Conformance report for reference [\#307](https://github.com/nlohmann/json/issues/307)
- Document the best way to serialize/deserialize user defined types to json [\#298](https://github.com/nlohmann/json/issues/298)
- Add StringView template typename to basic\_json [\#297](https://github.com/nlohmann/json/issues/297)
- \[Improvement\] Add option to remove exceptions [\#296](https://github.com/nlohmann/json/issues/296)
- Performance in miloyip/nativejson-benchmark [\#202](https://github.com/nlohmann/json/issues/202)
- conversion from/to user-defined types [\#435](https://github.com/nlohmann/json/pull/435) ([nlohmann](https://github.com/nlohmann))
- Fix documentation error [\#430](https://github.com/nlohmann/json/pull/430) ([vjon](https://github.com/vjon))
## [v2.0.10](https://github.com/nlohmann/json/releases/tag/v2.0.10) (2017-01-02)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.9...v2.0.10)
- Heap-buffer-overflow \(OSS-Fuzz issue 367\) [\#412](https://github.com/nlohmann/json/issues/412)
- Heap-buffer-overflow \(OSS-Fuzz issue 366\) [\#411](https://github.com/nlohmann/json/issues/411)
- Use-of-uninitialized-value \(OSS-Fuzz issue 347\) [\#409](https://github.com/nlohmann/json/issues/409)
- Heap-buffer-overflow \(OSS-Fuzz issue 344\) [\#408](https://github.com/nlohmann/json/issues/408)
- Heap-buffer-overflow \(OSS-Fuzz issue 343\) [\#407](https://github.com/nlohmann/json/issues/407)
- Heap-buffer-overflow \(OSS-Fuzz issue 342\) [\#405](https://github.com/nlohmann/json/issues/405)
- strerror throwing error in compiler VS2015 [\#403](https://github.com/nlohmann/json/issues/403)
- json::parse of std::string being underlined by Visual Studio [\#402](https://github.com/nlohmann/json/issues/402)
- Explicitly getting string without .dump\(\) [\#401](https://github.com/nlohmann/json/issues/401)
- Possible to speed up json::parse? [\#398](https://github.com/nlohmann/json/issues/398)
- the alphabetic order in the code influence console\_output. [\#396](https://github.com/nlohmann/json/issues/396)
- Execute tests with clang sanitizers [\#394](https://github.com/nlohmann/json/issues/394)
- Check if library can be used with ETL [\#361](https://github.com/nlohmann/json/issues/361)
- Feature/clang sanitize [\#410](https://github.com/nlohmann/json/pull/410) ([Daniel599](https://github.com/Daniel599))
- Add Doozer build badge [\#400](https://github.com/nlohmann/json/pull/400) ([andoma](https://github.com/andoma))
## [v2.0.9](https://github.com/nlohmann/json/releases/tag/v2.0.9) (2016-12-16)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.8...v2.0.9)
- \#pragma GCC diagnostic ignored "-Wdocumentation" [\#393](https://github.com/nlohmann/json/issues/393)
- How to parse this json file and write separate sub object as json files? [\#392](https://github.com/nlohmann/json/issues/392)
- Integer-overflow \(OSS-Fuzz issue 267\) [\#389](https://github.com/nlohmann/json/issues/389)
- Implement indefinite-length types from RFC 7049 [\#387](https://github.com/nlohmann/json/issues/387)
- template parameter "T" is not used in declaring the parameter types of function template [\#386](https://github.com/nlohmann/json/issues/386)
- Serializing json instances containing already serialized string values without escaping [\#385](https://github.com/nlohmann/json/issues/385)
- Add test cases from RFC 7049 [\#384](https://github.com/nlohmann/json/issues/384)
- Add a table of contents to the README file [\#383](https://github.com/nlohmann/json/issues/383)
- Update FAQ section in the guidelines for contributing [\#382](https://github.com/nlohmann/json/issues/382)
- Allow for forward declaring nlohmann::json [\#381](https://github.com/nlohmann/json/issues/381)
- Bug in overflow detection when parsing integers [\#380](https://github.com/nlohmann/json/issues/380)
- A unique name to mention the library? [\#377](https://github.com/nlohmann/json/issues/377)
- Support for comments. [\#376](https://github.com/nlohmann/json/issues/376)
- Non-unique keys in objects. [\#375](https://github.com/nlohmann/json/issues/375)
- Request: binary serialization/deserialization [\#358](https://github.com/nlohmann/json/issues/358)
- Replace class iterator and const\_iterator by using a single template class to reduce code. [\#395](https://github.com/nlohmann/json/pull/395) ([Bosswestfalen](https://github.com/Bosswestfalen))
- Clang: quiet a warning [\#391](https://github.com/nlohmann/json/pull/391) ([jaredgrubb](https://github.com/jaredgrubb))
- Fix issue \#380: Signed integer overflow check [\#390](https://github.com/nlohmann/json/pull/390) ([qwename](https://github.com/qwename))
## [v2.0.8](https://github.com/nlohmann/json/releases/tag/v2.0.8) (2016-12-02)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.7...v2.0.8)
- Reading from file [\#374](https://github.com/nlohmann/json/issues/374)
- Compiler warnings? [\#372](https://github.com/nlohmann/json/issues/372)
- docs: how to release a json object in memory? [\#371](https://github.com/nlohmann/json/issues/371)
- crash in dump [\#370](https://github.com/nlohmann/json/issues/370)
- Coverity issue \(FORWARD\_NULL\) in lexer\(std::istream& s\) [\#368](https://github.com/nlohmann/json/issues/368)
- json::parse on failed stream gets stuck [\#366](https://github.com/nlohmann/json/issues/366)
- Performance improvements [\#365](https://github.com/nlohmann/json/issues/365)
- 'to\_string' is not a member of 'std' [\#364](https://github.com/nlohmann/json/issues/364)
- Optional comment support. [\#363](https://github.com/nlohmann/json/issues/363)
- Loss of precision when serializing \<double\> [\#360](https://github.com/nlohmann/json/issues/360)
- Crash in dump\(\) from a static object [\#359](https://github.com/nlohmann/json/issues/359)
- json::parse\(...\) vs json j; j.parse\(...\) [\#357](https://github.com/nlohmann/json/issues/357)
- Hi, is there any method to dump json to string with the insert order rather than alphabets [\#356](https://github.com/nlohmann/json/issues/356)
- Provide an example of reading from an json with only a key that has an array of strings. [\#354](https://github.com/nlohmann/json/issues/354)
- Request: access with default value. [\#353](https://github.com/nlohmann/json/issues/353)
- {} and \[\] causes parser error. [\#352](https://github.com/nlohmann/json/issues/352)
- Reading a JSON file into a JSON object [\#351](https://github.com/nlohmann/json/issues/351)
- Request: 'emplace\_back' [\#349](https://github.com/nlohmann/json/issues/349)
- Is it possible to stream data through the json parser without storing everything in memory? [\#347](https://github.com/nlohmann/json/issues/347)
- pure virtual conversion operator [\#346](https://github.com/nlohmann/json/issues/346)
- Floating point precision lost [\#345](https://github.com/nlohmann/json/issues/345)
- unit-conversions SIGSEGV on armv7hl [\#303](https://github.com/nlohmann/json/issues/303)
- Coverity scan fails [\#299](https://github.com/nlohmann/json/issues/299)
- Using QString as string type [\#274](https://github.com/nlohmann/json/issues/274)
## [v2.0.7](https://github.com/nlohmann/json/releases/tag/v2.0.7) (2016-11-02)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.6...v2.0.7)
- JSON5 [\#348](https://github.com/nlohmann/json/issues/348)
- Check "Parsing JSON is a Minefield" [\#344](https://github.com/nlohmann/json/issues/344)
- Allow hex numbers [\#342](https://github.com/nlohmann/json/issues/342)
- Convert strings to numbers [\#341](https://github.com/nlohmann/json/issues/341)
- ""-operators ignore the length parameter [\#340](https://github.com/nlohmann/json/issues/340)
- JSON into std::tuple [\#339](https://github.com/nlohmann/json/issues/339)
- JSON into vector [\#335](https://github.com/nlohmann/json/issues/335)
- Installing with Homebrew on Mac Errors \(El Capitan\) [\#331](https://github.com/nlohmann/json/issues/331)
- g++ make check results in error [\#312](https://github.com/nlohmann/json/issues/312)
- Cannot convert from 'json' to 'char' [\#276](https://github.com/nlohmann/json/issues/276)
- Please add a Pretty-Print option for arrays to stay always in one line [\#229](https://github.com/nlohmann/json/issues/229)
- Conversion to STL map\<string, vector\<int\>\> gives error [\#220](https://github.com/nlohmann/json/issues/220)
- std::unorderd\_map cannot be used as ObjectType [\#164](https://github.com/nlohmann/json/issues/164)
- fix minor grammar/style issue in README.md [\#336](https://github.com/nlohmann/json/pull/336) ([seeekr](https://github.com/seeekr))
## [v2.0.6](https://github.com/nlohmann/json/releases/tag/v2.0.6) (2016-10-15)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.5...v2.0.6)
- How to handle json files? [\#333](https://github.com/nlohmann/json/issues/333)
- This file requires compiler and library support .... [\#332](https://github.com/nlohmann/json/issues/332)
- Segmentation fault on saving json to file [\#326](https://github.com/nlohmann/json/issues/326)
- parse error - unexpected \<uninitialized\> with 2.0.5 [\#325](https://github.com/nlohmann/json/issues/325)
- Add nested object capability to pointers [\#323](https://github.com/nlohmann/json/issues/323)
- Fix usage examples' comments for std::multiset [\#322](https://github.com/nlohmann/json/issues/322)
- json\_unit runs forever when executed in build directory [\#319](https://github.com/nlohmann/json/issues/319)
- Visual studio 2015 update3 true != TRUE [\#317](https://github.com/nlohmann/json/issues/317)
- releasing single header file in compressed format [\#316](https://github.com/nlohmann/json/issues/316)
- json object from std::ifstream [\#315](https://github.com/nlohmann/json/issues/315)
- make has\_mapped\_type struct friendly [\#324](https://github.com/nlohmann/json/pull/324) ([vpetrigo](https://github.com/vpetrigo))
- Fix usage examples' comments for std::multiset [\#321](https://github.com/nlohmann/json/pull/321) ([vasild](https://github.com/vasild))
- Include dir relocation [\#318](https://github.com/nlohmann/json/pull/318) ([ChristophJud](https://github.com/ChristophJud))
- trivial documentation fix [\#313](https://github.com/nlohmann/json/pull/313) ([5tefan](https://github.com/5tefan))
## [v2.0.5](https://github.com/nlohmann/json/releases/tag/v2.0.5) (2016-09-14)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.4...v2.0.5)
- \[feature request\]: schema validator and comments [\#311](https://github.com/nlohmann/json/issues/311)
- make json\_benchmarks no longer working in 2.0.4 [\#310](https://github.com/nlohmann/json/issues/310)
- Segmentation fault \(core dumped\) [\#309](https://github.com/nlohmann/json/issues/309)
- No matching member function for call to 'get\_impl' [\#308](https://github.com/nlohmann/json/issues/308)
## [v2.0.4](https://github.com/nlohmann/json/releases/tag/v2.0.4) (2016-09-11)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.3...v2.0.4)
- Parsing fails without space at end of file [\#306](https://github.com/nlohmann/json/issues/306)
- json schema validator [\#305](https://github.com/nlohmann/json/issues/305)
- Unused variable warning [\#304](https://github.com/nlohmann/json/issues/304)
## [v2.0.3](https://github.com/nlohmann/json/releases/tag/v2.0.3) (2016-08-31)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.2...v2.0.3)
- warning C4706: assignment within conditional expression [\#295](https://github.com/nlohmann/json/issues/295)
- Strip comments / Minify [\#294](https://github.com/nlohmann/json/issues/294)
- Q: Is it possible to build json tree from already UTF8 encoded values? [\#293](https://github.com/nlohmann/json/issues/293)
- Equality operator results in array when assigned object [\#292](https://github.com/nlohmann/json/issues/292)
- Support for integers not from the range \[-\(2\*\*53\)+1, \(2\*\*53\)-1\] in parser [\#291](https://github.com/nlohmann/json/issues/291)
- Support for iterator-range parsing [\#290](https://github.com/nlohmann/json/issues/290)
- Horribly inconsistent behavior between const/non-const reference in operator \[\] \(\) [\#289](https://github.com/nlohmann/json/issues/289)
- Silently get numbers into smaller types [\#288](https://github.com/nlohmann/json/issues/288)
- Incorrect parsing of large int64\_t numbers [\#287](https://github.com/nlohmann/json/issues/287)
- \[question\]: macro to disable floating point support [\#284](https://github.com/nlohmann/json/issues/284)
- unit-constructor1.cpp: Fix floating point truncation warning [\#300](https://github.com/nlohmann/json/pull/300) ([t-b](https://github.com/t-b))
## [v2.0.2](https://github.com/nlohmann/json/releases/tag/v2.0.2) (2016-07-31)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.1...v2.0.2)
- can function dump\(\) return string in the order I push in the json object ? [\#286](https://github.com/nlohmann/json/issues/286)
- Error on the Mac: Undefined symbols for architecture x86\_64 [\#285](https://github.com/nlohmann/json/issues/285)
- value\(\) does not work with \_json\_pointer types [\#283](https://github.com/nlohmann/json/issues/283)
- Build error for std::int64 [\#282](https://github.com/nlohmann/json/issues/282)
- strings can't be accessed after dump\(\)-\>parse\(\) - type is lost [\#281](https://github.com/nlohmann/json/issues/281)
- Easy serialization of classes [\#280](https://github.com/nlohmann/json/issues/280)
- recursive data structures [\#277](https://github.com/nlohmann/json/issues/277)
- hexify\(\) function emits conversion warning [\#270](https://github.com/nlohmann/json/issues/270)
- let the makefile choose the correct sed [\#279](https://github.com/nlohmann/json/pull/279) ([murinicanor](https://github.com/murinicanor))
- Update hexify to use array lookup instead of ternary \(\#270\) [\#275](https://github.com/nlohmann/json/pull/275) ([dtoma](https://github.com/dtoma))
## [v2.0.1](https://github.com/nlohmann/json/releases/tag/v2.0.1) (2016-06-28)
[Full Changelog](https://github.com/nlohmann/json/compare/v2.0.0...v2.0.1)
- Compilation error. [\#273](https://github.com/nlohmann/json/issues/273)
- dump\(\) performance degradation in v2 [\#272](https://github.com/nlohmann/json/issues/272)
- fixed a tiny typo [\#271](https://github.com/nlohmann/json/pull/271) ([thelostt](https://github.com/thelostt))
## [v2.0.0](https://github.com/nlohmann/json/releases/tag/v2.0.0) (2016-06-23)
[Full Changelog](https://github.com/nlohmann/json/compare/v1.1.0...v2.0.0)
- json::diff generates incorrect patch when removing multiple array elements. [\#269](https://github.com/nlohmann/json/issues/269)
- Docs - What does Json\[key\] return? [\#267](https://github.com/nlohmann/json/issues/267)
- Compiler Errors With JSON.hpp [\#265](https://github.com/nlohmann/json/issues/265)
- Throw exception instead of crashing my app [\#264](https://github.com/nlohmann/json/issues/264)
- Ambiguous push\_back and operator+= overloads [\#263](https://github.com/nlohmann/json/issues/263)
- Preseving order of items in json [\#262](https://github.com/nlohmann/json/issues/262)
- '\' char problem in strings [\#261](https://github.com/nlohmann/json/issues/261)
- VS2015 compile fail [\#260](https://github.com/nlohmann/json/issues/260)
- -Wconversion warning [\#259](https://github.com/nlohmann/json/issues/259)
- Maybe a bug [\#258](https://github.com/nlohmann/json/issues/258)
- Few tests failed on Visual C++ 2015 [\#257](https://github.com/nlohmann/json/issues/257)
- Access keys when iteration with new for loop C++11 [\#256](https://github.com/nlohmann/json/issues/256)
- multiline text values [\#255](https://github.com/nlohmann/json/issues/255)
- Error when using json in g++ [\#254](https://github.com/nlohmann/json/issues/254)
- is the release 2.0? [\#253](https://github.com/nlohmann/json/issues/253)
- concatenate objects [\#252](https://github.com/nlohmann/json/issues/252)
- Encoding [\#251](https://github.com/nlohmann/json/issues/251)
- Unable to build example for constructing json object with stringstreams [\#250](https://github.com/nlohmann/json/issues/250)
- Hexadecimal support [\#249](https://github.com/nlohmann/json/issues/249)
- Update long-term goals [\#246](https://github.com/nlohmann/json/issues/246)
- Contribution To This Json Project [\#245](https://github.com/nlohmann/json/issues/245)
- Trouble using parser with initial dictionary [\#243](https://github.com/nlohmann/json/issues/243)
- Unit test fails when doing a CMake out-of-tree build [\#241](https://github.com/nlohmann/json/issues/241)
- -Wconversion warnings [\#239](https://github.com/nlohmann/json/issues/239)
- Additional integration options [\#237](https://github.com/nlohmann/json/issues/237)
- .get\<std::string\>\(\) works for non spaced string but returns as array for spaced/longer strings [\#236](https://github.com/nlohmann/json/issues/236)
- ambiguous overload for 'push\_back' and 'operator+=' [\#235](https://github.com/nlohmann/json/issues/235)
- Can't use basic\_json::iterator as a base iterator for std::move\_iterator [\#233](https://github.com/nlohmann/json/issues/233)
- json object's creation can freezes execution [\#231](https://github.com/nlohmann/json/issues/231)
- Incorrect dumping of parsed numbers with exponents, but without decimal places [\#230](https://github.com/nlohmann/json/issues/230)
- double values are serialized with commas as decimal points [\#228](https://github.com/nlohmann/json/issues/228)
- Move semantics with std::initializer\_list [\#225](https://github.com/nlohmann/json/issues/225)
- replace emplace [\#224](https://github.com/nlohmann/json/issues/224)
- abort during getline in yyfill [\#223](https://github.com/nlohmann/json/issues/223)
- free\(\): invalid pointer error in GCC 5.2.1 [\#221](https://github.com/nlohmann/json/issues/221)
- Error compile Android NDK error: 'strtof' is not a member of 'std' [\#219](https://github.com/nlohmann/json/issues/219)
- Wrong link in the README.md [\#217](https://github.com/nlohmann/json/issues/217)
- Wide character strings not supported [\#216](https://github.com/nlohmann/json/issues/216)
- Memory allocations using range-based for loops [\#214](https://github.com/nlohmann/json/issues/214)
- would you like to support gcc 4.8.1? [\#211](https://github.com/nlohmann/json/issues/211)
- Reading concatenated json's from an istream [\#210](https://github.com/nlohmann/json/issues/210)
- Conflicting typedef of ssize\_t on Windows 32 bit when using Boost.Python [\#204](https://github.com/nlohmann/json/issues/204)
- Inconsistency between operator\[\] and push\_back [\#203](https://github.com/nlohmann/json/issues/203)
- Small bugs in json.hpp \(get\_number\) and unit.cpp \(non-standard integer type test\) [\#199](https://github.com/nlohmann/json/issues/199)
- GCC/clang floating point parsing bug in strtod\(\) [\#195](https://github.com/nlohmann/json/issues/195)
- What is within scope? [\#192](https://github.com/nlohmann/json/issues/192)
- Bugs in miloyip/nativejson-benchmark: roundtrips [\#187](https://github.com/nlohmann/json/issues/187)
- Floating point exceptions [\#181](https://github.com/nlohmann/json/issues/181)
- Integer conversion to unsigned [\#178](https://github.com/nlohmann/json/issues/178)
- map string string fails to compile [\#176](https://github.com/nlohmann/json/issues/176)
- In basic\_json::basic\_json\(const CompatibleArrayType& val\), the requirement of CompatibleArrayType is not strict enough. [\#174](https://github.com/nlohmann/json/issues/174)
- Provide a FAQ [\#163](https://github.com/nlohmann/json/issues/163)
- Implicit assignment to std::string fails [\#144](https://github.com/nlohmann/json/issues/144)
- Fix Issue \#265 [\#266](https://github.com/nlohmann/json/pull/266) ([06needhamt](https://github.com/06needhamt))
- Define CMake/CTest tests [\#247](https://github.com/nlohmann/json/pull/247) ([robertmrk](https://github.com/robertmrk))
- Out of tree builds and a few other miscellaneous CMake cleanups. [\#242](https://github.com/nlohmann/json/pull/242) ([ChrisKitching](https://github.com/ChrisKitching))
- Implement additional integration options [\#238](https://github.com/nlohmann/json/pull/238) ([robertmrk](https://github.com/robertmrk))
- make serialization locale-independent [\#232](https://github.com/nlohmann/json/pull/232) ([nlohmann](https://github.com/nlohmann))
- fixes \#223 by updating README.md [\#227](https://github.com/nlohmann/json/pull/227) ([kevin--](https://github.com/kevin--))
- Use namespace std for int64\_t and uint64\_t [\#226](https://github.com/nlohmann/json/pull/226) ([lv-zheng](https://github.com/lv-zheng))
- Added missing cerrno header to fix ERANGE compile error on android [\#222](https://github.com/nlohmann/json/pull/222) ([Teemperor](https://github.com/Teemperor))
- Corrected readme [\#218](https://github.com/nlohmann/json/pull/218) ([Annihil](https://github.com/Annihil))
- Create PULL\_REQUEST\_TEMPLATE.md [\#213](https://github.com/nlohmann/json/pull/213) ([whackashoe](https://github.com/whackashoe))
- fixed noexcept; added constexpr [\#208](https://github.com/nlohmann/json/pull/208) ([nlohmann](https://github.com/nlohmann))
- Add support for afl-fuzz testing [\#207](https://github.com/nlohmann/json/pull/207) ([mykter](https://github.com/mykter))
- replaced ssize\_t occurrences with auto \(addresses \#204\) [\#205](https://github.com/nlohmann/json/pull/205) ([nlohmann](https://github.com/nlohmann))
- Fixed issue \#199 - Small bugs in json.hpp \(get\_number\) and unit.cpp \(non-standard integer type test\) [\#200](https://github.com/nlohmann/json/pull/200) ([twelsby](https://github.com/twelsby))
- Fix broken link [\#197](https://github.com/nlohmann/json/pull/197) ([vog](https://github.com/vog))
- Issue \#195 - update Travis to Trusty due to gcc/clang strtod\(\) bug [\#196](https://github.com/nlohmann/json/pull/196) ([twelsby](https://github.com/twelsby))
- Issue \#178 - Extending support to full uint64\_t/int64\_t range and unsigned type \(updated\) [\#193](https://github.com/nlohmann/json/pull/193) ([twelsby](https://github.com/twelsby))
## [v1.1.0](https://github.com/nlohmann/json/releases/tag/v1.1.0) (2016-01-24)
[Full Changelog](https://github.com/nlohmann/json/compare/v1.0.0...v1.1.0)
- Small error in pull \#185 [\#194](https://github.com/nlohmann/json/issues/194)
- Bugs in miloyip/nativejson-benchmark: floating-point parsing [\#186](https://github.com/nlohmann/json/issues/186)
- Floating point equality [\#185](https://github.com/nlohmann/json/issues/185)
- Unused variables in catch [\#180](https://github.com/nlohmann/json/issues/180)
- Typo in documentation [\#179](https://github.com/nlohmann/json/issues/179)
- JSON performance benchmark comparision [\#177](https://github.com/nlohmann/json/issues/177)
- Since re2c is often ignored in pull requests, it may make sense to make a contributing.md file [\#175](https://github.com/nlohmann/json/issues/175)
- Question about exceptions [\#173](https://github.com/nlohmann/json/issues/173)
- Android? [\#172](https://github.com/nlohmann/json/issues/172)
- Cannot index by key of type static constexpr const char\* [\#171](https://github.com/nlohmann/json/issues/171)
- Add assertions [\#168](https://github.com/nlohmann/json/issues/168)
- MSVC 2015 build fails when attempting to compare object\_t [\#167](https://github.com/nlohmann/json/issues/167)
- Member detector is not portable [\#166](https://github.com/nlohmann/json/issues/166)
- Unnecessary const\_cast [\#162](https://github.com/nlohmann/json/issues/162)
- Question about get\_ref\(\) [\#128](https://github.com/nlohmann/json/issues/128)
- range based for loop for objects [\#83](https://github.com/nlohmann/json/issues/83)
- Consider submitting this to the Boost Library Incubator [\#66](https://github.com/nlohmann/json/issues/66)
- Fixed Issue \#186 - add strto\(f|d|ld\) overload wrappers, "-0.0" special case and FP trailing zero [\#191](https://github.com/nlohmann/json/pull/191) ([twelsby](https://github.com/twelsby))
- Issue \#185 - remove approx\(\) and use \#pragma to kill warnings [\#190](https://github.com/nlohmann/json/pull/190) ([twelsby](https://github.com/twelsby))
- Fixed Issue \#171 - added two extra template overloads of operator\[\] for T\* arguments [\#189](https://github.com/nlohmann/json/pull/189) ([twelsby](https://github.com/twelsby))
- Fixed issue \#167 - removed operator ValueType\(\) condition for VS2015 [\#188](https://github.com/nlohmann/json/pull/188) ([twelsby](https://github.com/twelsby))
- Implementation of get\_ref\(\) [\#184](https://github.com/nlohmann/json/pull/184) ([dariomt](https://github.com/dariomt))
- Fixed some typos in CONTRIBUTING.md [\#182](https://github.com/nlohmann/json/pull/182) ([nibroc](https://github.com/nibroc))
## [v1.0.0](https://github.com/nlohmann/json/releases/tag/v1.0.0) (2015-12-27)
[Full Changelog](https://github.com/nlohmann/json/compare/v1.0.0-rc1...v1.0.0)
- add key name to exception [\#160](https://github.com/nlohmann/json/issues/160)
- Getting member discarding qualifyer [\#159](https://github.com/nlohmann/json/issues/159)
- basic\_json::iterator::value\(\) output includes quotes while basic\_json::iterator::key\(\) doesn't [\#158](https://github.com/nlohmann/json/issues/158)
- Indexing `const basic\_json\<\>` with `const basic\_string\<char\>` [\#157](https://github.com/nlohmann/json/issues/157)
- token\_type\_name\(token\_type t\): not all control paths return a value [\#156](https://github.com/nlohmann/json/issues/156)
- prevent json.hpp from emitting compiler warnings [\#154](https://github.com/nlohmann/json/issues/154)
- json::parse\(string\) does not check utf8 bom [\#152](https://github.com/nlohmann/json/issues/152)
- unsigned 64bit values output as signed [\#151](https://github.com/nlohmann/json/issues/151)
- Wish feature: json5 [\#150](https://github.com/nlohmann/json/issues/150)
- Unable to compile on MSVC 2015 with SDL checking enabled: This function or variable may be unsafe. [\#149](https://github.com/nlohmann/json/issues/149)
- "Json Object" type does not keep object order [\#148](https://github.com/nlohmann/json/issues/148)
- dump\(\) convert strings encoded by utf-8 to shift-jis on windows 10. [\#147](https://github.com/nlohmann/json/issues/147)
- Unable to get field names in a json object [\#145](https://github.com/nlohmann/json/issues/145)
- Question: Is the use of incomplete type correct? [\#138](https://github.com/nlohmann/json/issues/138)
- json.hpp:5746:32: error: 'to\_string' is not a member of 'std' [\#136](https://github.com/nlohmann/json/issues/136)
- Bug in basic\_json::operator\[\] const overload [\#135](https://github.com/nlohmann/json/issues/135)
- wrong enable\_if for const pointer \(instead of pointer-to-const\) [\#134](https://github.com/nlohmann/json/issues/134)
- overload of at\(\) with default value [\#133](https://github.com/nlohmann/json/issues/133)
- Splitting source [\#132](https://github.com/nlohmann/json/issues/132)
- Question about get\_ptr\(\) [\#127](https://github.com/nlohmann/json/issues/127)
- Visual Studio 14 Debug assertion failed [\#125](https://github.com/nlohmann/json/issues/125)
- Memory leak in face of exceptions [\#118](https://github.com/nlohmann/json/issues/118)
- Find and Count for arrays [\#117](https://github.com/nlohmann/json/issues/117)
- dynamically constructing an arbitrarily nested object [\#114](https://github.com/nlohmann/json/issues/114)
- Returning any data type [\#113](https://github.com/nlohmann/json/issues/113)
- Compile error with g++ 4.9.3 cygwin 64-bit [\#112](https://github.com/nlohmann/json/issues/112)
- insert json array issue with gcc4.8.2 [\#110](https://github.com/nlohmann/json/issues/110)
- error: unterminated raw string [\#109](https://github.com/nlohmann/json/issues/109)
- vector\<json\> copy constructor really weird [\#108](https://github.com/nlohmann/json/issues/108)
- \[clang-3.6.2\] string/sstream with number to json issue [\#107](https://github.com/nlohmann/json/issues/107)
- maintaining order of keys during iteration [\#106](https://github.com/nlohmann/json/issues/106)
- object field accessors [\#103](https://github.com/nlohmann/json/issues/103)
- v8pp and json [\#95](https://github.com/nlohmann/json/issues/95)
- Wishlist [\#65](https://github.com/nlohmann/json/issues/65)
- Windows/Visual Studio \(through 2013\) is unsupported [\#62](https://github.com/nlohmann/json/issues/62)
- Replace sprintf with hex function, this fixes \#149 [\#153](https://github.com/nlohmann/json/pull/153) ([whackashoe](https://github.com/whackashoe))
- Fix character skipping after a surrogate pair [\#146](https://github.com/nlohmann/json/pull/146) ([robertmrk](https://github.com/robertmrk))
- Detect correctly pointer-to-const [\#137](https://github.com/nlohmann/json/pull/137) ([dariomt](https://github.com/dariomt))
- disabled "CopyAssignable" test for MSVC in Debug mode, see \#125 [\#131](https://github.com/nlohmann/json/pull/131) ([dariomt](https://github.com/dariomt))
- removed stream operator for iterator, resolution for \#125 [\#130](https://github.com/nlohmann/json/pull/130) ([dariomt](https://github.com/dariomt))
- fixed typos in comments for examples [\#129](https://github.com/nlohmann/json/pull/129) ([dariomt](https://github.com/dariomt))
- Remove superfluous inefficiency [\#126](https://github.com/nlohmann/json/pull/126) ([d-frey](https://github.com/d-frey))
- remove invalid parameter '-stdlib=libc++' in CMakeLists.txt [\#124](https://github.com/nlohmann/json/pull/124) ([emvivre](https://github.com/emvivre))
- exception-safe object creation, fixes \#118 [\#122](https://github.com/nlohmann/json/pull/122) ([d-frey](https://github.com/d-frey))
- Fix small oversight. [\#121](https://github.com/nlohmann/json/pull/121) ([ColinH](https://github.com/ColinH))
- Overload parse\(\) to accept an rvalue reference [\#120](https://github.com/nlohmann/json/pull/120) ([silverweed](https://github.com/silverweed))
- Use the right variable name in doc string [\#115](https://github.com/nlohmann/json/pull/115) ([whoshuu](https://github.com/whoshuu))
## [v1.0.0-rc1](https://github.com/nlohmann/json/releases/tag/v1.0.0-rc1) (2015-07-26)
- Finish documenting the public interface in Doxygen [\#102](https://github.com/nlohmann/json/issues/102)
- Binary string causes numbers to be dumped as hex [\#101](https://github.com/nlohmann/json/issues/101)
- failed to iterator json object with reverse\_iterator [\#100](https://github.com/nlohmann/json/issues/100)
- 'noexcept' : unknown override specifier [\#99](https://github.com/nlohmann/json/issues/99)
- json float parsing problem [\#98](https://github.com/nlohmann/json/issues/98)
- Adjust wording to JSON RFC [\#97](https://github.com/nlohmann/json/issues/97)
- 17 MB / 90 MB repo size!? [\#96](https://github.com/nlohmann/json/issues/96)
- static analysis warnings [\#94](https://github.com/nlohmann/json/issues/94)
- reverse\_iterator operator inheritance problem [\#93](https://github.com/nlohmann/json/issues/93)
- init error [\#92](https://github.com/nlohmann/json/issues/92)
- access by \(const\) reference [\#91](https://github.com/nlohmann/json/issues/91)
- is\_integer and is\_float tests [\#90](https://github.com/nlohmann/json/issues/90)
- Nonstandard integer type [\#89](https://github.com/nlohmann/json/issues/89)
- static library build [\#84](https://github.com/nlohmann/json/issues/84)
- lexer::get\_number return NAN [\#82](https://github.com/nlohmann/json/issues/82)
- MinGW have no std::to\_string [\#80](https://github.com/nlohmann/json/issues/80)
- Incorrect behaviour of basic\_json::count method [\#78](https://github.com/nlohmann/json/issues/78)
- Invoking is\_array\(\) function creates "null" value [\#77](https://github.com/nlohmann/json/issues/77)
- dump\(\) / parse\(\) not idempotent [\#76](https://github.com/nlohmann/json/issues/76)
- Handle infinity and NaN cases [\#70](https://github.com/nlohmann/json/issues/70)
- errors in g++-4.8.1 [\#68](https://github.com/nlohmann/json/issues/68)
- Keys when iterating over objects [\#67](https://github.com/nlohmann/json/issues/67)
- Compilation results in tons of warnings [\#64](https://github.com/nlohmann/json/issues/64)
- Complete brief documentation [\#61](https://github.com/nlohmann/json/issues/61)
- Double quotation mark is not parsed correctly [\#60](https://github.com/nlohmann/json/issues/60)
- Get coverage back to 100% [\#58](https://github.com/nlohmann/json/issues/58)
- erase elements using iterators [\#57](https://github.com/nlohmann/json/issues/57)
- Removing item from array [\#56](https://github.com/nlohmann/json/issues/56)
- Serialize/Deserialize like PHP? [\#55](https://github.com/nlohmann/json/issues/55)
- Numbers as keys [\#54](https://github.com/nlohmann/json/issues/54)
- Why are elements alphabetized on key while iterating? [\#53](https://github.com/nlohmann/json/issues/53)
- Document erase, count, and iterators key and value [\#52](https://github.com/nlohmann/json/issues/52)
- Do not use std::to\_string [\#51](https://github.com/nlohmann/json/issues/51)
- Supported compilers [\#50](https://github.com/nlohmann/json/issues/50)
- Confused about iterating through json objects [\#49](https://github.com/nlohmann/json/issues/49)
- Use non-member begin/end [\#48](https://github.com/nlohmann/json/issues/48)
- Erase key [\#47](https://github.com/nlohmann/json/issues/47)
- Key iterator [\#46](https://github.com/nlohmann/json/issues/46)
- Add count member function [\#45](https://github.com/nlohmann/json/issues/45)
- Problem getting vector \(array\) of strings [\#44](https://github.com/nlohmann/json/issues/44)
- Compilation error due to assuming that private=public [\#43](https://github.com/nlohmann/json/issues/43)
- Use of deprecated implicit copy constructor [\#42](https://github.com/nlohmann/json/issues/42)
- Printing attribute names [\#39](https://github.com/nlohmann/json/issues/39)
- dumping a small number\_float just outputs 0.000000 [\#37](https://github.com/nlohmann/json/issues/37)
- find is error [\#32](https://github.com/nlohmann/json/issues/32)
- Avoid using spaces when encoding without pretty print [\#31](https://github.com/nlohmann/json/issues/31)
- Cannot encode long numbers [\#30](https://github.com/nlohmann/json/issues/30)
- segmentation fault when iterating over empty arrays/objects [\#28](https://github.com/nlohmann/json/issues/28)
- Creating an empty array [\#27](https://github.com/nlohmann/json/issues/27)
- Custom allocator support [\#25](https://github.com/nlohmann/json/issues/25)
- make the type of the used string container customizable [\#20](https://github.com/nlohmann/json/issues/20)
- Improper parsing of JSON string "\\" [\#17](https://github.com/nlohmann/json/issues/17)
- create a header-only version [\#16](https://github.com/nlohmann/json/issues/16)
- Don't return "const values" [\#15](https://github.com/nlohmann/json/issues/15)
- Add to\_string overload for indentation [\#13](https://github.com/nlohmann/json/issues/13)
- string parser does not recognize uncompliant strings [\#12](https://github.com/nlohmann/json/issues/12)
- possible double-free in find function [\#11](https://github.com/nlohmann/json/issues/11)
- UTF-8 encoding/deconding/testing [\#10](https://github.com/nlohmann/json/issues/10)
- move code into namespace [\#9](https://github.com/nlohmann/json/issues/9)
- free functions for explicit objects and arrays in initializer lists [\#8](https://github.com/nlohmann/json/issues/8)
- unique\_ptr for ownership [\#7](https://github.com/nlohmann/json/issues/7)
- Add unit tests [\#4](https://github.com/nlohmann/json/issues/4)
- Drop C++98 support [\#3](https://github.com/nlohmann/json/issues/3)
- Test case coverage [\#2](https://github.com/nlohmann/json/issues/2)
- Runtime error in Travis job [\#1](https://github.com/nlohmann/json/issues/1)
- Keyword 'inline' is useless when member functions are defined in headers [\#87](https://github.com/nlohmann/json/pull/87) ([ahamez](https://github.com/ahamez))
- Remove useless typename [\#86](https://github.com/nlohmann/json/pull/86) ([ahamez](https://github.com/ahamez))
- Avoid warning with Xcode's clang [\#85](https://github.com/nlohmann/json/pull/85) ([ahamez](https://github.com/ahamez))
- Fix typos [\#73](https://github.com/nlohmann/json/pull/73) ([aqnouch](https://github.com/aqnouch))
- Replace `default\_callback` function with `nullptr` and check for null… [\#72](https://github.com/nlohmann/json/pull/72) ([aburgh](https://github.com/aburgh))
- support enum [\#71](https://github.com/nlohmann/json/pull/71) ([likebeta](https://github.com/likebeta))
- Fix performance regression introduced with the parsing callback feature. [\#69](https://github.com/nlohmann/json/pull/69) ([aburgh](https://github.com/aburgh))
- Improve the implementations of the comparission-operators [\#63](https://github.com/nlohmann/json/pull/63) ([Florianjw](https://github.com/Florianjw))
- Fix compilation of json\_unit with GCC 5 [\#59](https://github.com/nlohmann/json/pull/59) ([dkopecek](https://github.com/dkopecek))
- Parse streams incrementally. [\#40](https://github.com/nlohmann/json/pull/40) ([aburgh](https://github.com/aburgh))
- Feature/small float serialization [\#38](https://github.com/nlohmann/json/pull/38) ([jrandall](https://github.com/jrandall))
- template version with re2c scanner [\#36](https://github.com/nlohmann/json/pull/36) ([nlohmann](https://github.com/nlohmann))
- more descriptive documentation in example [\#33](https://github.com/nlohmann/json/pull/33) ([luxe](https://github.com/luxe))
- Fix string conversion under Clang [\#26](https://github.com/nlohmann/json/pull/26) ([wancw](https://github.com/wancw))
- Fixed dumping of strings [\#24](https://github.com/nlohmann/json/pull/24) ([Teemperor](https://github.com/Teemperor))
- Added a remark to the readme that coverage is GCC only for now [\#23](https://github.com/nlohmann/json/pull/23) ([Teemperor](https://github.com/Teemperor))
- Unicode escaping [\#22](https://github.com/nlohmann/json/pull/22) ([Teemperor](https://github.com/Teemperor))
- Implemented the JSON spec for string parsing for everything but the \uXXXX escaping [\#21](https://github.com/nlohmann/json/pull/21) ([Teemperor](https://github.com/Teemperor))
- add the std iterator typedefs to iterator and const\_iterator [\#19](https://github.com/nlohmann/json/pull/19) ([kirkshoop](https://github.com/kirkshoop))
- Fixed escaped quotes [\#18](https://github.com/nlohmann/json/pull/18) ([Teemperor](https://github.com/Teemperor))
- Fix double delete on std::bad\_alloc exception [\#14](https://github.com/nlohmann/json/pull/14) ([elliotgoodrich](https://github.com/elliotgoodrich))
- Added CMake and lcov [\#6](https://github.com/nlohmann/json/pull/6) ([Teemperor](https://github.com/Teemperor))
- Version 2.0 [\#5](https://github.com/nlohmann/json/pull/5) ([nlohmann](https://github.com/nlohmann))
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2013-2017 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+139
View File
@@ -0,0 +1,139 @@
.PHONY: pretty clean ChangeLog.md
# used programs
RE2C = re2c
SED = sed
# main target
all:
$(MAKE) -C test
# clean up
clean:
rm -fr json_unit json_benchmarks fuzz fuzz-testing *.dSYM test/*.dSYM
rm -fr benchmarks/files/numbers/*.json
$(MAKE) clean -Cdoc
$(MAKE) clean -Ctest
##########################################################################
# unit tests
##########################################################################
# build unit tests
json_unit:
@$(MAKE) json_unit -C test
# run unit tests
check:
$(MAKE) check -C test
check-fast:
$(MAKE) check -C test TEST_PATTERN=""
##########################################################################
# documentation tests
##########################################################################
# compile example files and check output
doctest:
$(MAKE) check_output -C doc
##########################################################################
# fuzzing
##########################################################################
# the overall fuzz testing target
fuzz_testing:
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
$(MAKE) parse_afl_fuzzer -C test CXX=afl-clang++
mv test/parse_afl_fuzzer fuzz-testing/fuzzer
find test/data/json_tests -size -5k -name *json | xargs -I{} cp "{}" fuzz-testing/testcases
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
fuzz_testing_cbor:
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
$(MAKE) parse_cbor_fuzzer -C test CXX=afl-clang++
mv test/parse_cbor_fuzzer fuzz-testing/fuzzer
find test/data -size -5k -name *.cbor | xargs -I{} cp "{}" fuzz-testing/testcases
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
fuzz_testing_msgpack:
rm -fr fuzz-testing
mkdir -p fuzz-testing fuzz-testing/testcases fuzz-testing/out
$(MAKE) parse_msgpack_fuzzer -C test CXX=afl-clang++
mv test/parse_msgpack_fuzzer fuzz-testing/fuzzer
find test/data -size -5k -name *.msgpack | xargs -I{} cp "{}" fuzz-testing/testcases
@echo "Execute: afl-fuzz -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer"
fuzzing-start:
afl-fuzz -S fuzzer1 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer2 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer3 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer4 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer5 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer6 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -S fuzzer7 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer > /dev/null &
afl-fuzz -M fuzzer0 -i fuzz-testing/testcases -o fuzz-testing/out fuzz-testing/fuzzer
fuzzing-stop:
-killall fuzzer
-killall afl-fuzz
##########################################################################
# static analyzer
##########################################################################
# call cppcheck on the main header file
cppcheck:
cppcheck --enable=warning --inconclusive --force --std=c++11 src/json.hpp --error-exitcode=1
# run clang sanitize (we are overrding the CXXFLAGS provided by travis in order to use gcc's libstdc++)
clang_sanitize: clean
CXX=clang++ CXXFLAGS="-g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" $(MAKE)
##########################################################################
# maintainer targets
##########################################################################
# create scanner with re2c
re2c: src/json.hpp.re2c
$(RE2C) -W --utf-8 --encoding-policy fail --bit-vectors --nested-ifs --no-debug-info $< | $(SED) '1d' > src/json.hpp
# pretty printer
pretty:
astyle --style=allman --indent=spaces=4 --indent-modifiers \
--indent-switches --indent-preproc-block --indent-preproc-define \
--indent-col1-comments --pad-oper --pad-header --align-pointer=type \
--align-reference=type --add-brackets --convert-tabs --close-templates \
--lineend=linux --preserve-date --suffix=none --formatted \
src/json.hpp src/json.hpp.re2c test/src/*.cpp \
benchmarks/benchmarks.cpp doc/examples/*.cpp
##########################################################################
# benchmarks
##########################################################################
# benchmarks
json_benchmarks: benchmarks/benchmarks.cpp benchmarks/benchpress.hpp benchmarks/cxxopts.hpp src/json.hpp
cd benchmarks/files/numbers ; python generate.py
$(CXX) -std=c++11 -pthread $(CXXFLAGS) -DNDEBUG -O3 -flto -I src -I benchmarks $< $(LDFLAGS) -o $@
./json_benchmarks
##########################################################################
# changelog
##########################################################################
NEXT_VERSION ?= "unreleased"
ChangeLog.md:
github_changelog_generator -o ChangeLog.md --simple-list --release-url https://github.com/nlohmann/json/releases/tag/%s --future-release $(NEXT_VERSION)
gsed -i 's|https://github.com/nlohmann/json/releases/tag/HEAD|https://github.com/nlohmann/json/tree/HEAD|' ChangeLog.md
gsed -i '2i All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).' ChangeLog.md
+854
View File
@@ -0,0 +1,854 @@
[![JSON for Modern C++](https://raw.githubusercontent.com/nlohmann/json/master/doc/json.gif)](https://github.com/nlohmann/json/releases)
[![Build Status](https://travis-ci.org/nlohmann/json.svg?branch=master)](https://travis-ci.org/nlohmann/json)
[![Build Status](https://ci.appveyor.com/api/projects/status/1acb366xfyg3qybk/branch/develop?svg=true)](https://ci.appveyor.com/project/nlohmann/json)
[![Build status](https://doozer.io/badge/nlohmann/json/buildstatus/develop)](https://doozer.io/user/nlohmann/json)
[![Coverage Status](https://img.shields.io/coveralls/nlohmann/json.svg)](https://coveralls.io/r/nlohmann/json)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/5550/badge.svg)](https://scan.coverity.com/projects/nlohmann-json)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](http://melpon.org/wandbox/permlink/4NEU6ZZMoM9lpIex)
[![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://nlohmann.github.io/json)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
[![Github Releases](https://img.shields.io/github/release/nlohmann/json.svg)](https://github.com/nlohmann/json/releases)
[![Github Issues](https://img.shields.io/github/issues/nlohmann/json.svg)](http://github.com/nlohmann/json/issues)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/289/badge)](https://bestpractices.coreinfrastructure.org/projects/289)
- [Design goals](#design-goals)
- [Integration](#integration)
- [Examples](#examples)
- [JSON as first-class data type](#json-as-first-class-data-type)
- [Serialization / Deserialization](#serialization--deserialization)
- [STL-like access](#stl-like-access)
- [Conversion from STL containers](#conversion-from-stl-containers)
- [JSON Pointer and JSON Patch](#json-pointer-and-json-patch)
- [Implicit conversions](#implicit-conversions)
- [Conversions to/from arbitrary types](#arbitrary-types-conversions)
- [Binary formats (CBOR and MessagePack)](#binary-formats-cbor-and-messagepack)
- [Supported compilers](#supported-compilers)
- [License](#license)
- [Thanks](#thanks)
- [Notes](#notes)
- [Execute unit tests](#execute-unit-tests)
## Design goals
There are myriads of [JSON](http://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of modern C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you'll know what I mean.
- **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/src/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings.
- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks. To maintain high quality, the project is following the [Core Infrastructure Initiative (CII) best practices](https://bestpractices.coreinfrastructure.org/projects/289).
Other aspects were not so important to us:
- **Memory efficiency**. Each JSON object has an overhead of one pointer (the maximal size of a union) and one enumeration element (1 byte). The default generalization uses the following C++ data types: `std::string` for strings, `int64_t`, `uint64_t` or `double` for numbers, `std::map` for objects, `std::vector` for arrays, and `bool` for Booleans. However, you can template the generalized class `basic_json` to your needs.
- **Speed**. There are certainly [faster JSON libraries](https://github.com/miloyip/nativejson-benchmark#parsing-time) out there. However, if your goal is to speed up your development by adding JSON support with a single header, then this library is the way to go. If you know how to use a `std::vector` or `std::map`, you are already set.
See the [contribution guidelines](https://github.com/nlohmann/json/blob/master/.github/CONTRIBUTING.md#please-dont) for more information.
## Integration
The single required source, file `json.hpp` is in the `src` directory or [released here](https://github.com/nlohmann/json/releases). All you need to do is add
```cpp
#include "json.hpp"
// for convenience
using json = nlohmann::json;
```
to the files you want to use JSON objects. That's it. Do not forget to set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang).
:beer: If you are using OS X and [Homebrew](http://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann_json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann_json --HEAD`.
## Examples
Beside the examples below, you may want to check the [documentation](https://nlohmann.github.io/json/) where each function contains a separate code example (e.g., check out [`emplace()`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a602f275f0359ab181221384989810604.html#a602f275f0359ab181221384989810604)). All [example files](https://github.com/nlohmann/json/tree/develop/doc/examples) can be compiled and executed on their own (e.g., file [emplace.cpp](https://github.com/nlohmann/json/blob/develop/doc/examples/emplace.cpp)).
### JSON as first-class data type
Here are some examples to give you an idea how to use the class.
Assume you want to create the JSON object
```json
{
"pi": 3.141,
"happy": true,
"name": "Niels",
"nothing": null,
"answer": {
"everything": 42
},
"list": [1, 0, 2],
"object": {
"currency": "USD",
"value": 42.99
}
}
```
With the JSON class, you could write:
```cpp
// create an empty structure (null)
json j;
// add a number that is stored as double (note the implicit conversion of j to an object)
j["pi"] = 3.141;
// add a Boolean that is stored as bool
j["happy"] = true;
// add a string that is stored as std::string
j["name"] = "Niels";
// add another null object by passing nullptr
j["nothing"] = nullptr;
// add an object inside the object
j["answer"]["everything"] = 42;
// add an array that is stored as std::vector (using an initializer list)
j["list"] = { 1, 0, 2 };
// add another object (using an initializer list of pairs)
j["object"] = { {"currency", "USD"}, {"value", 42.99} };
// instead, you could also write (which looks very similar to the JSON above)
json j2 = {
{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{"answer", {
{"everything", 42}
}},
{"list", {1, 0, 2}},
{"object", {
{"currency", "USD"},
{"value", 42.99}
}}
};
```
Note that in all these cases, you never need to "tell" the compiler which JSON value you want to use. If you want to be explicit or express some edge cases, the functions `json::array` and `json::object` will help:
```cpp
// a way to express the empty array []
json empty_array_explicit = json::array();
// ways to express the empty object {}
json empty_object_implicit = json({});
json empty_object_explicit = json::object();
// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]]
json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) };
```
### Serialization / Deserialization
#### To/from strings
You can create an object (deserialization) by appending `_json` to a string literal:
```cpp
// create object from string literal
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json;
// or even nicer with a raw string literal
auto j2 = R"(
{
"happy": true,
"pi": 3.141
}
)"_json;
// or explicitly
auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }");
```
You can also get a string representation (serialize):
```cpp
// explicit conversion to string
std::string s = j.dump(); // {\"happy\":true,\"pi\":3.141}
// serialization with pretty printing
// pass in the amount of spaces to indent
std::cout << j.dump(4) << std::endl;
// {
// "happy": true,
// "pi": 3.141
// }
```
#### To/from streams (e.g. files, string streams)
You can also use streams to serialize and deserialize:
```cpp
// deserialize from standard input
json j;
std::cin >> j;
// serialize to standard output
std::cout << j;
// the setw manipulator was overloaded to set the indentation for pretty printing
std::cout << std::setw(4) << j << std::endl;
```
These operators work for any subclasses of `std::istream` or `std::ostream`. Here is the same example with files:
```cpp
// read a JSON file
std::ifstream i("file.json");
json j;
i >> j;
// write prettified JSON to another file
std::ofstream o("pretty.json");
o << std::setw(4) << j << std::endl;
```
Please note that setting the exception bit for `failbit` is inappropriate for this use case. It will result in program termination due to the `noexcept` specifier in use.
#### Read from iterator range
You can also read JSON from an iterator range; that is, from any container accessible by iterators whose content is stored as contiguous byte sequence, for instance a `std::vector<uint8_t>`:
```cpp
std::vector<uint8_t> v = {'t', 'r', 'u', 'e'};
json j = json::parse(v.begin(), v.end());
```
You may leave the iterators for the range [begin, end):
```cpp
std::vector<uint8_t> v = {'t', 'r', 'u', 'e'};
json j = json::parse(v);
```
### STL-like access
We designed the JSON class to behave just like an STL container. In fact, it satisfies the [**ReversibleContainer**](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirement.
```cpp
// create an array using push_back
json j;
j.push_back("foo");
j.push_back(1);
j.push_back(true);
// also use emplace_back
j.emplace_back(1.78);
// iterate the array
for (json::iterator it = j.begin(); it != j.end(); ++it) {
std::cout << *it << '\n';
}
// range-based for
for (auto& element : j) {
std::cout << element << '\n';
}
// getter/setter
const std::string tmp = j[0];
j[1] = 42;
bool foo = j.at(2);
// comparison
j == "[\"foo\", 1, true]"_json; // true
// other stuff
j.size(); // 3 entries
j.empty(); // false
j.type(); // json::value_t::array
j.clear(); // the array is empty again
// convenience type checkers
j.is_null();
j.is_boolean();
j.is_number();
j.is_object();
j.is_array();
j.is_string();
// create an object
json o;
o["foo"] = 23;
o["bar"] = false;
o["baz"] = 3.141;
// also use emplace
o.emplace("weather", "sunny");
// special iterator member functions for objects
for (json::iterator it = o.begin(); it != o.end(); ++it) {
std::cout << it.key() << " : " << it.value() << "\n";
}
// find an entry
if (o.find("foo") != o.end()) {
// there is an entry with key "foo"
}
// or simpler using count()
int foo_present = o.count("foo"); // 1
int fob_present = o.count("fob"); // 0
// delete an entry
o.erase("foo");
```
### Conversion from STL containers
Any sequence container (`std::array`, `std::vector`, `std::deque`, `std::forward_list`, `std::list`) whose values can be used to construct JSON types (e.g., integers, floating point numbers, Booleans, string types, or again STL containers described in this section) can be used to create a JSON array. The same holds for similar associative containers (`std::set`, `std::multiset`, `std::unordered_set`, `std::unordered_multiset`), but in these cases the order of the elements of the array depends how the elements are ordered in the respective STL container.
```cpp
std::vector<int> c_vector {1, 2, 3, 4};
json j_vec(c_vector);
// [1, 2, 3, 4]
std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6};
json j_deque(c_deque);
// [1.2, 2.3, 3.4, 5.6]
std::list<bool> c_list {true, true, false, true};
json j_list(c_list);
// [true, true, false, true]
std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
json j_flist(c_flist);
// [12345678909876, 23456789098765, 34567890987654, 45678909876543]
std::array<unsigned long, 4> c_array {{1, 2, 3, 4}};
json j_array(c_array);
// [1, 2, 3, 4]
std::set<std::string> c_set {"one", "two", "three", "four", "one"};
json j_set(c_set); // only one entry for "one" is used
// ["four", "one", "three", "two"]
std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"};
json j_uset(c_uset); // only one entry for "one" is used
// maybe ["two", "three", "four", "one"]
std::multiset<std::string> c_mset {"one", "two", "one", "four"};
json j_mset(c_mset); // both entries for "one" are used
// maybe ["one", "two", "one", "four"]
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
json j_umset(c_umset); // both entries for "one" are used
// maybe ["one", "two", "one", "four"]
```
Likewise, any associative key-value containers (`std::map`, `std::multimap`, `std::unordered_map`, `std::unordered_multimap`) whose keys can construct an `std::string` and whose values can be used to construct JSON types (see examples above) can be used to to create a JSON object. Note that in case of multimaps only one key is used in the JSON object and the value depends on the internal order of the STL container.
```cpp
std::map<std::string, int> c_map { {"one", 1}, {"two", 2}, {"three", 3} };
json j_map(c_map);
// {"one": 1, "three": 3, "two": 2 }
std::unordered_map<const char*, double> c_umap { {"one", 1.2}, {"two", 2.3}, {"three", 3.4} };
json j_umap(c_umap);
// {"one": 1.2, "two": 2.3, "three": 3.4}
std::multimap<std::string, bool> c_mmap { {"one", true}, {"two", true}, {"three", false}, {"three", true} };
json j_mmap(c_mmap); // only one entry for key "three" is used
// maybe {"one": true, "two": true, "three": true}
std::unordered_multimap<std::string, bool> c_ummap { {"one", true}, {"two", true}, {"three", false}, {"three", true} };
json j_ummap(c_ummap); // only one entry for key "three" is used
// maybe {"one": true, "two": true, "three": true}
```
### JSON Pointer and JSON Patch
The library supports **JSON Pointer** ([RFC 6901](https://tools.ietf.org/html/rfc6901)) as alternative means to address structured values. On top of this, **JSON Patch** ([RFC 6902](https://tools.ietf.org/html/rfc6902)) allows to describe differences between two JSON values - effectively allowing patch and diff operations known from Unix.
```cpp
// a JSON value
json j_original = R"({
"baz": ["one", "two", "three"],
"foo": "bar"
})"_json;
// access members with a JSON pointer (RFC 6901)
j_original["/baz/1"_json_pointer];
// "two"
// a JSON patch (RFC 6902)
json j_patch = R"([
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo"}
])"_json;
// apply the patch
json j_result = j_original.patch(j_patch);
// {
// "baz": "boo",
// "hello": ["world"]
// }
// calculate a JSON patch from two JSON values
json::diff(j_result, j_original);
// [
// { "op":" replace", "path": "/baz", "value": ["one", "two", "three"] },
// { "op": "remove","path": "/hello" },
// { "op": "add", "path": "/foo", "value": "bar" }
// ]
```
### Implicit conversions
The type of the JSON object is determined automatically by the expression to store. Likewise, the stored value is implicitly converted.
```cpp
// strings
std::string s1 = "Hello, world!";
json js = s1;
std::string s2 = js;
// Booleans
bool b1 = true;
json jb = b1;
bool b2 = jb;
// numbers
int i = 42;
json jn = i;
double f = jn;
// etc.
```
You can also explicitly ask for the value:
```cpp
std::string vs = js.get<std::string>();
bool vb = jb.get<bool>();
int vi = jn.get<int>();
// etc.
```
### Arbitrary types conversions
Every type can be serialized in JSON, not just STL-containers and scalar types. Usually, you would do something along those lines:
```cpp
namespace ns {
// a simple struct to model a person
struct person {
std::string name;
std::string address;
int age;
};
}
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
// convert to JSON: copy each value into the JSON object
json j;
j["name"] = p.name;
j["address"] = p.address;
j["age"] = p.age;
// ...
// convert from JSON: copy each value from the JSON object
ns::person p {
j["name"].get<std::string>(),
j["address"].get<std::string>(),
j["age"].get<int>()
};
```
It works, but that's quite a lot of boilerplate... Fortunately, there's a better way:
```cpp
// create a person
ns::person p {"Ned Flanders", "744 Evergreen Terrace", 60};
// conversion: person -> json
json j = p;
std::cout << j << std::endl;
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
// conversion: json -> person
ns::person p2 = j;
// that's it
assert(p == p2);
```
#### Basic usage
To make this work with one of your types, you only need to provide two functions:
```cpp
using nlohmann::json;
namespace ns {
void to_json(json& j, const person& p) {
j = json{{"name", p.name}, {"address", p.address}, {"age", p.age}};
}
void from_json(const json& j, person& p) {
p.name = j["name"].get<std::string>();
p.address = j["address"].get<std::string>();
p.age = j["age"].get<int>();
}
} // namespace ns
```
That's all! When calling the `json` constructor with your type, your custom `to_json` method will be automatically called.
Likewise, when calling `get<your_type>()`, the `from_json` method will be called.
Some important things:
* Those methods **MUST** be in your type's namespace (which can be the global namespace), or the library will not be able to locate them (in this example, they are in namespace `ns`, where `person` is defined).
* When using `get<your_type>()`, `your_type` **MUST** be [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible). (There is a way to bypass this requirement described later.)
#### How do I convert third-party types?
This requires a bit more advanced technique. But first, let's see how this conversion mechanism works:
The library uses **JSON Serializers** to convert types to json.
The default serializer for `nlohmann::json` is `nlohmann::adl_serializer` (ADL means [Argument-Dependent Lookup](http://en.cppreference.com/w/cpp/language/adl)).
It is implemented like this (simplified):
```cpp
template <typename T>
struct adl_serializer {
static void to_json(json& j, const T& value) {
// calls the "to_json" method in T's namespace
}
static void from_json(const json& j, T& value) {
// same thing, but with the "from_json" method
}
};
```
This serializer works fine when you have control over the type's namespace. However, what about `boost::optional`, or `std::filesystem::path` (C++17)? Hijacking the `boost` namespace is pretty bad, and it's illegal to add something other than template specializations to `std`...
To solve this, you need to add a specialization of `adl_serializer` to the `nlohmann` namespace, here's an example:
```cpp
// partial specialization (full specialization works too)
namespace nlohmann {
template <typename T>
struct adl_serializer<boost::optional<T>> {
static void to_json(json& j, const boost::optional<T>& opt) {
if (opt == boost::none) {
j = nullptr;
} else {
j = *opt; // this will call adl_serializer<T>::to_json which will
// find the free function to_json in T's namespace!
}
}
static void from_json(const json& j, boost::optional<T>& opt) {
if (!j.is_null()) {
opt = j.get<T>(); // same as above, but with
// adl_serializer<T>::from_json
}
}
};
}
```
#### How can I use `get()` for non-default constructible/non-copyable types?
There is a way, if your type is [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible). You will need to specialize the `adl_serializer` as well, but with a special `from_json` overload:
```cpp
struct move_only_type {
move_only_type() = delete;
move_only_type(int ii): i(ii) {}
move_only_type(const move_only_type&) = delete;
move_only_type(move_only_type&&) = default;
int i;
};
namespace nlohmann {
template <>
struct adl_serializer<move_only_type> {
// note: the return type is no longer 'void', and the method only takes
// one argument
static move_only_type from_json(const json& j) {
return {j.get<int>()};
}
// Here's the catch! You must provide a to_json method! Otherwise you
// will not be able to convert move_only_type to json, since you fully
// specialized adl_serializer on that type
static void to_json(json& j, move_only_type t) {
j = t.i;
}
};
}
```
#### Can I write my own serializer? (Advanced use)
Yes. You might want to take a look at [`unit-udt.cpp`](https://github.com/nlohmann/json/blob/develop/test/src/unit-udt.cpp) in the test suite, to see a few examples.
If you write your own serializer, you'll need to do a few things:
* use a different `basic_json` alias than `nlohmann::json` (the last template parameter of `basic_json` is the `JSONSerializer`)
* use your `basic_json` alias (or a template parameter) in all your `to_json`/`from_json` methods
* use `nlohmann::to_json` and `nlohmann::from_json` when you need ADL
Here is an example, without simplifications, that only accepts types with a size <= 32, and uses ADL.
```cpp
// You should use void as a second template argument
// if you don't need compile-time checks on T
template<typename T, typename SFINAE = typename std::enable_if<sizeof(T) <= 32>::type>
struct less_than_32_serializer {
template <typename BasicJsonType>
static void to_json(BasicJsonType& j, T value) {
// we want to use ADL, and call the correct to_json overload
using nlohmann::to_json; // this method is called by adl_serializer,
// this is where the magic happens
to_json(j, value);
}
template <typename BasicJsonType>
static void from_json(const BasicJsonType& j, T& value) {
// same thing here
using nlohmann::from_json;
from_json(j, value);
}
};
```
Be **very** careful when reimplementing your serializer, you can stack overflow if you don't pay attention:
```cpp
template <typename T, void>
struct bad_serializer
{
template <typename BasicJsonType>
static void to_json(BasicJsonType& j, const T& value) {
// this calls BasicJsonType::json_serializer<T>::to_json(j, value);
// if BasicJsonType::json_serializer == bad_serializer ... oops!
j = value;
}
template <typename BasicJsonType>
static void to_json(const BasicJsonType& j, T& value) {
// this calls BasicJsonType::json_serializer<T>::from_json(j, value);
// if BasicJsonType::json_serializer == bad_serializer ... oops!
value = j.template get<T>(); // oops!
}
};
```
### Binary formats (CBOR and MessagePack)
Though JSON is a ubiquitous data format, it is not a very compact format suitable for data exchange, for instance over a network. Hence, the library supports [CBOR](http://cbor.io) (Concise Binary Object Representation) and [MessagePack](http://msgpack.org) to efficiently encode JSON values to byte vectors and to decode such vectors.
```cpp
// create a JSON value
json j = R"({"compact": true, "schema": 0})"_json;
// serialize to CBOR
std::vector<uint8_t> v_cbor = json::to_cbor(j);
// 0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 0x74, 0xf5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00
// roundtrip
json j_from_cbor = json::from_cbor(v_cbor);
// serialize to MessagePack
std::vector<uint8_t> v_msgpack = json::to_msgpack(j);
// 0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00
// roundtrip
json j_from_msgpack = json::from_msgpack(v_msgpack);
```
## Supported compilers
Though it's 2016 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
- GCC 4.9 - 6.0 (and possibly later)
- Clang 3.4 - 3.9 (and possibly later)
- Microsoft Visual C++ 2015 / Build Tools 14.0.25123.0 (and possibly later)
I would be happy to learn about other compilers/versions.
Please note:
- GCC 4.8 does not work because of two bugs ([55817](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55817) and [57824](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824)) in the C++11 support. Note there is a [pull request](https://github.com/nlohmann/json/pull/212) to fix some of the issues.
- Android defaults to using very old compilers and C++ libraries. To fix this, add the following to your `Application.mk`. This will switch to the LLVM C++ library, the Clang compiler, and enable C++11 and other features disabled by default.
```
APP_STL := c++_shared
NDK_TOOLCHAIN_VERSION := clang3.6
APP_CPPFLAGS += -frtti -fexceptions
```
The code compiles successfully with [Android NDK](https://developer.android.com/ndk/index.html?hl=ml), Revision 9 - 11 (and possibly later) and [CrystaX's Android NDK](https://www.crystax.net/en/android/ndk) version 10.
- For GCC running on MinGW or Android SDK, the error `'to_string' is not a member of 'std'` (or similarly, for `strtod`) may occur. Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to [this site](http://tehsausage.com/mingw-to-string) and [this discussion](https://github.com/nlohmann/json/issues/136) for information on how to fix this bug. For Android NDK using `APP_STL := gnustl_static`, please refer to [this discussion](https://github.com/nlohmann/json/issues/219).
The following compilers are currently used in continuous integration at [Travis](https://travis-ci.org/nlohmann/json) and [AppVeyor](https://ci.appveyor.com/project/nlohmann/json):
| Compiler | Operating System | Version String |
|-----------------|------------------------------|----------------|
| GCC 4.9.3 | Ubuntu 14.04.4 LTS | g++-4.9 (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 |
| GCC 5.3.0 | Ubuntu 14.04.4 LTS | g++-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204 |
| GCC 6.1.1 | Ubuntu 14.04.4 LTS | g++-6 (Ubuntu 6.1.1-3ubuntu11~14.04.1) 6.1.1 20160511 |
| Clang 3.6.0 | Ubuntu 14.04.4 LTS | clang version 3.6.0 (tags/RELEASE_360/final) |
| Clang 3.6.1 | Ubuntu 14.04.4 LTS | clang version 3.6.1 (tags/RELEASE_361/final) |
| Clang 3.6.2 | Ubuntu 14.04.4 LTS | clang version 3.6.2 (tags/RELEASE_362/final) |
| Clang 3.7.0 | Ubuntu 14.04.4 LTS | clang version 3.7.0 (tags/RELEASE_370/final) |
| Clang 3.7.1 | Ubuntu 14.04.4 LTS | clang version 3.7.1 (tags/RELEASE_371/final) |
| Clang 3.8.0 | Ubuntu 14.04.4 LTS | clang version 3.8.0 (tags/RELEASE_380/final) |
| Clang 3.8.1 | Ubuntu 14.04.4 LTS | clang version 3.8.1 (tags/RELEASE_381/final) |
| Clang Xcode 6.4 | Darwin Kernel Version 14.3.0 (OSX 10.10.3) | Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) |
| Clang Xcode 7.3 | Darwin Kernel Version 15.0.0 (OSX 10.10.5) | Apple LLVM version 7.3.0 (clang-703.0.29) |
| Clang Xcode 8.0 | Darwin Kernel Version 15.6.0 | Apple LLVM version 8.0.0 (clang-800.0.38) |
| Clang Xcode 8.1 | Darwin Kernel Version 16.1.0 (macOS 10.12.1) | Apple LLVM version 8.0.0 (clang-800.0.42.1) |
| Clang Xcode 8.2 | Darwin Kernel Version 16.1.0 (macOS 10.12.1) | Apple LLVM version 8.0.0 (clang-800.0.42.1) |
| Visual Studio 14 2015 | Windows Server 2012 R2 (x64) | Microsoft (R) Build Engine version 14.0.25123.0 |
## License
<img align="right" src="http://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png">
The class is licensed under the [MIT License](http://opensource.org/licenses/MIT):
Copyright &copy; 2013-2017 [Niels Lohmann](http://nlohmann.me)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## Thanks
I deeply appreciate the help of the following people.
- [Teemperor](https://github.com/Teemperor) implemented CMake support and lcov integration, realized escape and Unicode handling in the string parser, and fixed the JSON serialization.
- [elliotgoodrich](https://github.com/elliotgoodrich) fixed an issue with double deletion in the iterator classes.
- [kirkshoop](https://github.com/kirkshoop) made the iterators of the class composable to other libraries.
- [wancw](https://github.com/wanwc) fixed a bug that hindered the class to compile with Clang.
- Tomas Åblad found a bug in the iterator implementation.
- [Joshua C. Randall](https://github.com/jrandall) fixed a bug in the floating-point serialization.
- [Aaron Burghardt](https://github.com/aburgh) implemented code to parse streams incrementally. Furthermore, he greatly improved the parser class by allowing the definition of a filter function to discard undesired elements while parsing.
- [Daniel Kopeček](https://github.com/dkopecek) fixed a bug in the compilation with GCC 5.0.
- [Florian Weber](https://github.com/Florianjw) fixed a bug in and improved the performance of the comparison operators.
- [Eric Cornelius](https://github.com/EricMCornelius) pointed out a bug in the handling with NaN and infinity values. He also improved the performance of the string escaping.
- [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums.
- [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio.
- [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators and helped with numerous hints and improvements. In particular, he pushed forward the implementation of user-defined types.
- [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling.
- [dariomt](https://github.com/dariomt) fixed some typos in the examples.
- [Daniel Frey](https://github.com/d-frey) cleaned up some pointers and implemented exception-safe memory allocation.
- [Colin Hirsch](https://github.com/ColinH) took care of a small namespace issue.
- [Huu Nguyen](https://github.com/whoshuu) correct a variable name in the documentation.
- [Silverweed](https://github.com/silverweed) overloaded `parse()` to accept an rvalue reference.
- [dariomt](https://github.com/dariomt) fixed a subtlety in MSVC type support and implemented the `get_ref()` function to get a reference to stored values.
- [ZahlGraf](https://github.com/ZahlGraf) added a workaround that allows compilation using Android NDK.
- [whackashoe](https://github.com/whackashoe) replaced a function that was marked as unsafe by Visual Studio.
- [406345](https://github.com/406345) fixed two small warnings.
- [Glen Fernandes](https://github.com/glenfe) noted a potential portability problem in the `has_mapped_type` function.
- [Corbin Hughes](https://github.com/nibroc) fixed some typos in the contribution guidelines.
- [twelsby](https://github.com/twelsby) fixed the array subscript operator, an issue that failed the MSVC build, and floating-point parsing/dumping. He further added support for unsigned integer numbers and implemented better roundtrip support for parsed numbers.
- [Volker Diels-Grabsch](https://github.com/vog) fixed a link in the README file.
- [msm-](https://github.com/msm-) added support for american fuzzy lop.
- [Annihil](https://github.com/Annihil) fixed an example in the README file.
- [Themercee](https://github.com/Themercee) noted a wrong URL in the README file.
- [Lv Zheng](https://github.com/lv-zheng) fixed a namespace issue with `int64_t` and `uint64_t`.
- [abc100m](https://github.com/abc100m) analyzed the issues with GCC 4.8 and proposed a [partial solution](https://github.com/nlohmann/json/pull/212).
- [zewt](https://github.com/zewt) added useful notes to the README file about Android.
- [Róbert Márki](https://github.com/robertmrk) added a fix to use move iterators and improved the integration via CMake.
- [Chris Kitching](https://github.com/ChrisKitching) cleaned up the CMake files.
- [Tom Needham](https://github.com/06needhamt) fixed a subtle bug with MSVC 2015 which was also proposed by [Michael K.](https://github.com/Epidal).
- [Mário Feroldi](https://github.com/thelostt) fixed a small typo.
- [duncanwerner](https://github.com/duncanwerner) found a really embarrassing performance regression in the 2.0.0 release.
- [Damien](https://github.com/dtoma) fixed one of the last conversion warnings.
- [Thomas Braun](https://github.com/t-b) fixed a warning in a test case.
- [Théo DELRIEU](https://github.com/theodelrieu) patiently and constructively oversaw the long way toward [iterator-range parsing](https://github.com/nlohmann/json/issues/290). He also implemented the magic behind the serialization/deserialization of user-defined types.
- [Stefan](https://github.com/5tefan) fixed a minor issue in the documentation.
- [Vasil Dimov](https://github.com/vasild) fixed the documentation regarding conversions from `std::multiset`.
- [ChristophJud](https://github.com/ChristophJud) overworked the CMake files to ease project inclusion.
- [Vladimir Petrigo](https://github.com/vpetrigo) made a SFINAE hack more readable.
- [Denis Andrejew](https://github.com/seeekr) fixed a grammar issue in the README file.
- [Pierre-Antoine Lacaze](https://github.com/palacaze) found a subtle bug in the `dump()` function.
- [TurpentineDistillery](https://github.com/TurpentineDistillery) pointed to [`std::locale::classic()`](http://en.cppreference.com/w/cpp/locale/locale/classic) to avoid too much locale joggling, found some nice performance improvements in the parser and improved the benchmarking code.
- [cgzones](https://github.com/cgzones) had an idea how to fix the Coverity scan.
- [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning.
- [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check.
- [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one.
- [Daniel599](https://github.com/Daniel599) helped to get Travis execute the tests with Clang's sanitizers.
- [Jonathan Lee](https://github.com/vjon) fixed an example in the README file.
- [gnzlbg](https://github.com/gnzlbg) supported the implementation of user-defined types.
- [Alexej Harm](https://github.com/qis) helped to get the user-defined types working with Visual Studio.
- [Jared Grubb](https://github.com/jaredgrubb) supported the implementation of user-defined types.
- [EnricoBilla](https://github.com/EnricoBilla) noted a typo in an example.
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
## Notes
- The code contains numerous debug **assertions** which can be switched off by defining the preprocessor macro `NDEBUG`, see the [documentation of `assert`](http://en.cppreference.com/w/cpp/error/assert). In particular, note [`operator[]`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html#a2e26bd0b0168abb61f67ad5bcd5b9fa1) implements **unchecked access** for const objects: If the given key is not present, the behavior is undefined (think of a dereferenced null pointer) and yields an [assertion failure](https://github.com/nlohmann/json/issues/289) if assertions are switched on. If you are not sure whether an element in an object exists, use checked access with the [`at()` function](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html#a674de1ee73e6bf4843fc5dc1351fb726).
- As the exact type of a number is not defined in the [JSON specification](http://rfc7159.net/rfc7159), this library tries to choose the best fitting C++ number type automatically. As a result, the type `double` may be used to store numbers which may yield [**floating-point exceptions**](https://github.com/nlohmann/json/issues/181) in certain rare situations if floating-point exceptions have been unmasked in the calling code. These exceptions are not caused by the library and need to be fixed in the calling code, such as by re-masking the exceptions prior to calling library functions.
- The library supports **Unicode input** as follows:
- Only **UTF-8** encoded input is supported which is the default encoding for JSON according to [RFC 7159](http://rfc7159.net/rfc7159#rfc.section.8.1).
- Other encodings such as Latin-1, UTF-16, or UTF-32 are not supported and will yield parse errors.
- [Unicode noncharacters](http://www.unicode.org/faq/private_use.html#nonchar1) will not be replaced by the library.
- Invalid surrogates (e.g., incomplete pairs such as `\uDEAD`) will yield parse errors.
- The strings stored in the library are UTF-8 encoded. When using the default string type (`std::string`), note that its length/size functions return the number of stored bytes rather than the number of characters or glyphs.
- The code can be compiled without C++ **runtime type identification** features; that is, you can use the `-fno-rtti` compiler flag.
- **Exceptions** are used widly within the library. They can, however, be switched off with either using the compiler flag `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION`. In this case, exceptions are replaced by an `abort()` call.
## Execute unit tests
To compile and run the tests, you need to execute
```sh
$ make json_unit -Ctest
$ ./test/json_unit "*""
===============================================================================
All tests passed (11202052 assertions in 47 test cases)
```
Alternatively, you can use [CMake](https://cmake.org) and run
```sh
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ctest
```
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml).
-35
View File
@@ -1,35 +0,0 @@
# <small>nlohmann::</small>adl_serializer
```cpp
template<typename, typename>
struct adl_serializer;
```
Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose
`to_json`/`from_json` functions from the types' namespaces.
It is implemented similarly to
```cpp
template<typename ValueType>
struct adl_serializer {
template<typename BasicJsonType>
static void to_json(BasicJsonType& j, const T& value) {
// calls the "to_json" method in T's namespace
}
template<typename BasicJsonType>
static void from_json(const BasicJsonType& j, T& value) {
// same thing, but with the "from_json" method
}
};
```
## Member functions
- [**from_json**](from_json.md) - convert a JSON value to any value type
- [**to_json**](to_json.md) - convert any value type to a JSON value
## Version history
- Added in version 2.1.0.
-74
View File
@@ -1,74 +0,0 @@
# <small>nlohmann::adl_serializer::</small>from_json
```cpp
// (1)
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
// (2)
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
```
This function is usually called by the [`get()`](../basic_json/get.md) function of the [basic_json](../basic_json/index.md)
class (either explicitly or via the conversion operators).
1. This function is chosen for default-constructible value types.
2. This function is chosen for value types which are not default-constructible.
## Parameters
`j` (in)
: JSON value to read from
`val` (out)
: value to write to
## Return value
1. (none) -- the converted value is written to the output parameter `val`.
2. the JSON value `j` converted to `TargetType`
## Examples
??? example "Example: (1) Default-constructible type"
The example below shows how a `from_json` function can be implemented for a user-defined type. This function is
called by the `adl_serializer` when `get<ns::person>()` is called.
```cpp
--8<-- "examples/from_json__default_constructible.cpp"
```
Output:
```json
--8<-- "examples/from_json__default_constructible.output"
```
??? example "Example: (2) Non-default-constructible type"
The example below shows how a `from_json` is implemented as part of a specialization of the `adl_serializer` to
realize the conversion of a non-default-constructible type.
```cpp
--8<-- "examples/from_json__non_default_constructible.cpp"
```
Output:
```json
--8<-- "examples/from_json__non_default_constructible.output"
```
## See also
- [to_json](to_json.md)
## Version history
- Added in version 2.1.0.
File diff suppressed because one or more lines are too long
-157
View File
@@ -1,157 +0,0 @@
# nlohmann::adl_serializer::from_json
```
// (1)
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
// (2)
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
```
This function is usually called by the [`get()`](https://json.nlohmann.me/api/basic_json/get/index.md) function of the [basic_json](https://json.nlohmann.me/api/basic_json/index.md) class (either explicitly or via the conversion operators).
1. This function is chosen for default-constructible value types.
1. This function is chosen for value types which are not default-constructible.
## Parameters
`j` (in) : JSON value to read from
`val` (out) : value to write to
## Return value
1. (none) -- the converted value is written to the output parameter `val`.
1. the JSON value `j` converted to `TargetType`
## Examples
Example: (1) Default-constructible type
The example below shows how a `from_json` function can be implemented for a user-defined type. This function is called by the `adl_serializer` when `get<ns::person>()` is called.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace ns
{
// a simple struct to model a person
struct person
{
std::string name;
std::string address;
int age;
};
} // namespace ns
namespace ns
{
void from_json(const json& j, person& p)
{
j.at("name").get_to(p.name);
j.at("address").get_to(p.address);
j.at("age").get_to(p.age);
}
} // namespace ns
int main()
{
json j;
j["name"] = "Ned Flanders";
j["address"] = "744 Evergreen Terrace";
j["age"] = 60;
auto p = j.get<ns::person>();
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
}
```
Output:
```
Ned Flanders (60) lives in 744 Evergreen Terrace
```
Example: (2) Non-default-constructible type
The example below shows how a `from_json` is implemented as part of a specialization of the `adl_serializer` to realize the conversion of a non-default-constructible type.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace ns
{
// a simple struct to model a person (not default constructible)
struct person
{
person(std::string n, std::string a, int aa)
: name(std::move(n)), address(std::move(a)), age(aa)
{}
std::string name;
std::string address;
int age;
};
} // namespace ns
namespace nlohmann
{
template <>
struct adl_serializer<ns::person>
{
static ns::person from_json(const json& j)
{
return {j.at("name"), j.at("address"), j.at("age")};
}
// Here's the catch! You must provide a to_json method! Otherwise, you
// will not be able to convert person to json, since you fully
// specialized adl_serializer on that type
static void to_json(json& j, ns::person p)
{
j["name"] = p.name;
j["address"] = p.address;
j["age"] = p.age;
}
};
} // namespace nlohmann
int main()
{
json j;
j["name"] = "Ned Flanders";
j["address"] = "744 Evergreen Terrace";
j["age"] = 60;
auto p = j.get<ns::person>();
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
}
```
Output:
```
Ned Flanders (60) lives in 744 Evergreen Terrace
```
## See also
- [to_json](https://json.nlohmann.me/api/adl_serializer/to_json/index.md)
## Version history
- Added in version 2.1.0.
File diff suppressed because one or more lines are too long
-34
View File
@@ -1,34 +0,0 @@
# nlohmann::adl_serializer
```
template<typename, typename>
struct adl_serializer;
```
Serializer that uses ADL ([Argument-Dependent Lookup](https://en.cppreference.com/w/cpp/language/adl)) to choose `to_json`/`from_json` functions from the types' namespaces.
It is implemented similarly to
```
template<typename ValueType>
struct adl_serializer {
template<typename BasicJsonType>
static void to_json(BasicJsonType& j, const T& value) {
// calls the "to_json" method in T's namespace
}
template<typename BasicJsonType>
static void from_json(const BasicJsonType& j, T& value) {
// same thing, but with the "from_json" method
}
};
```
## Member functions
- [**from_json**](https://json.nlohmann.me/api/adl_serializer/from_json/index.md) - convert a JSON value to any value type
- [**to_json**](https://json.nlohmann.me/api/adl_serializer/to_json/index.md) - convert any value type to a JSON value
## Version history
- Added in version 2.1.0.
-43
View File
@@ -1,43 +0,0 @@
# <small>nlohmann::adl_serializer::</small>to_json
```cpp
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
```
This function is usually called by the constructors of the [basic_json](../basic_json/index.md) class.
## Parameters
`j` (out)
: JSON value to write to
`val` (in)
: value to read from
## Examples
??? example
The example below shows how a `to_json` function can be implemented for a user-defined type. This function is called
by the `adl_serializer` when the constructor `basic_json(ns::person)` is called.
```cpp
--8<-- "examples/to_json.cpp"
```
Output:
```json
--8<-- "examples/to_json.output"
```
## See also
- [from_json](from_json.md)
## Version history
- Added in version 2.1.0.
File diff suppressed because one or more lines are too long
-71
View File
@@ -1,71 +0,0 @@
# nlohmann::adl_serializer::to_json
```
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
```
This function is usually called by the constructors of the [basic_json](https://json.nlohmann.me/api/basic_json/index.md) class.
## Parameters
`j` (out) : JSON value to write to
`val` (in) : value to read from
## Examples
Example
The example below shows how a `to_json` function can be implemented for a user-defined type. This function is called by the `adl_serializer` when the constructor `basic_json(ns::person)` is called.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace ns
{
// a simple struct to model a person
struct person
{
std::string name;
std::string address;
int age;
};
} // namespace ns
namespace ns
{
void to_json(json& j, const person& p)
{
j = json{ {"name", p.name}, {"address", p.address}, {"age", p.age} };
}
} // namespace ns
int main()
{
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
json j = p;
std::cout << j << std::endl;
}
```
Output:
```
{"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
```
## See also
- [from_json](https://json.nlohmann.me/api/adl_serializer/from_json/index.md)
## Version history
- Added in version 2.1.0.
-338
View File
@@ -1,338 +0,0 @@
# <small>nlohmann::</small>basic_json
<small>Defined in header `<nlohmann/json.hpp>`</small>
```cpp
template<
template<typename U, typename V, typename... Args> class ObjectType = std::map,
template<typename U, typename... Args> class ArrayType = std::vector,
class StringType = std::string,
class BooleanType = bool,
class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
class NumberFloatType = double,
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer = adl_serializer,
class BinaryType = std::vector<std::uint8_t>,
class CustomBaseClass = void
>
class basic_json;
```
## Template parameters
| Template parameter | Description | Derived type |
|----------------------|---------------------------------------------------------------------------|---------------------------------------------|
| `ObjectType` | type for JSON objects | [`object_t`](object_t.md) |
| `ArrayType` | type for JSON arrays | [`array_t`](array_t.md) |
| `StringType` | type for JSON strings and object keys | [`string_t`](string_t.md) |
| `BooleanType` | type for JSON booleans | [`boolean_t`](boolean_t.md) |
| `NumberIntegerType` | type for JSON integer numbers | [`number_integer_t`](number_integer_t.md) |
| `NumberUnsignedType` | type for JSON unsigned integer numbers | [`number_unsigned_t`](number_unsigned_t.md) |
| `NumberFloatType` | type for JSON floating-point numbers | [`number_float_t`](number_float_t.md) |
| `AllocatorType` | type of the allocator to use | |
| `JSONSerializer` | the serializer to resolve internal calls to `to_json()` and `from_json()` | [`json_serializer`](json_serializer.md) |
| `BinaryType` | type for binary arrays | [`binary_t`](binary_t.md) |
| `CustomBaseClass` | extension point for user code | [`json_base_class_t`](json_base_class_t.md) |
## Specializations
- [**json**](../json.md) - default specialization
- [**ordered_json**](../ordered_json.md) - a specialization that maintains the insertion order of object keys
## Iterator invalidation
All operations that add values to an **array** ([`push_back`](push_back.md) , [`operator+=`](operator+=.md),
[`emplace_back`](emplace_back.md), [`insert`](insert.md), and [`operator[]`](operator%5B%5D.md) for a non-existing
index) can yield a reallocation, in which case all iterators (including the [`end()`](end.md) iterator) and all
references to the elements are invalidated.
For [`ordered_json`](../ordered_json.md), also all operations that add a value to an **object**
([`push_back`](push_back.md), [`operator+=`](operator+=.md), [`emplace`](emplace.md), [`insert`](insert.md),
[`update`](update.md), and [`operator[]`](operator%5B%5D.md) for a non-existing key) can yield a reallocation, in
which case all iterators (including the [`end()`](end.md) iterator) and all references to the elements are invalidated.
## Requirements
The class satisfies the following concept requirements:
### Basic
- [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible): JSON values can be
default-constructed. The result will be a JSON null value.
- [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible): A JSON value can be constructed
from an rvalue argument.
- [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible): A JSON value can be
copy-constructed from an lvalue expression.
- [MoveAssignable](https://en.cppreference.com/w/cpp/named_req/MoveAssignable): A JSON value can be assigned from an
rvalue argument.
- [CopyAssignable](https://en.cppreference.com/w/cpp/named_req/CopyAssignable): A JSON value can be copy-assigned from
an lvalue expression.
- [Destructible](https://en.cppreference.com/w/cpp/named_req/Destructible): JSON values can be destructed.
### Layout
- [StandardLayoutType](https://en.cppreference.com/w/cpp/named_req/StandardLayoutType): JSON values have
[standard layout](https://en.cppreference.com/w/cpp/language/data_members#Standard_layout): All non-static data
members are private and standard layout types, the class has no virtual functions or (virtual) base classes.
### Library-wide
- [EqualityComparable](https://en.cppreference.com/w/cpp/named_req/EqualityComparable): JSON values can be compared with
`==`, see [`operator==`](operator_eq.md).
- [LessThanComparable](https://en.cppreference.com/w/cpp/named_req/LessThanComparable): JSON values can be compared with
`<`, see [`operator<`](operator_le.md).
- [Swappable](https://en.cppreference.com/w/cpp/named_req/Swappable): Any JSON lvalue or rvalue of can be swapped with
any lvalue or rvalue of other compatible types, using unqualified function `swap`.
- [NullablePointer](https://en.cppreference.com/w/cpp/named_req/NullablePointer): JSON values can be compared against
`std::nullptr_t` objects which are used to model the `null` value.
### Container
- [Container](https://en.cppreference.com/w/cpp/named_req/Container): JSON values can be used like STL containers and
provide iterator access.
- [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer): JSON values can be used like
STL containers and provide reverse iterator access.
## Member types
- [**adl_serializer**](../adl_serializer/index.md) - the default serializer
- [**value_t**](value_t.md) - the JSON type enumeration
- [**json_pointer**](../json_pointer/index.md) - JSON Pointer implementation
- [**json_serializer**](json_serializer.md) - type of the serializer to for conversions from/to JSON
- [**error_handler_t**](error_handler_t.md) - type to choose behavior on decoding errors
- [**cbor_tag_handler_t**](cbor_tag_handler_t.md) - type to choose how to handle CBOR tags
- **initializer_list_t** - type for initializer lists of `basic_json` values
- [**input_format_t**](input_format_t.md) - type to choose the format to parse
- [**json_sax_t**](../json_sax/index.md) - type for SAX events
### Exceptions
- [**exception**](exception.md) - general exception of the `basic_json` class
- [**parse_error**](parse_error.md) - exception indicating a parse error
- [**invalid_iterator**](invalid_iterator.md) - exception indicating errors with iterators
- [**type_error**](type_error.md) - exception indicating executing a member function with a wrong type
- [**out_of_range**](out_of_range.md) - exception indicating access out of the defined range
- [**other_error**](other_error.md) - exception indicating other library errors
### Container types
| Type | Definition |
|--------------------------|-----------------------------------------------------------------------------------------------------------|
| `value_type` | `#!cpp basic_json` |
| `reference` | `#!cpp value_type&` |
| `const_reference` | `#!cpp const value_type&` |
| `difference_type` | `#!cpp std::ptrdiff_t` |
| `size_type` | `#!cpp std::size_t` |
| `allocator_type` | `#!cpp AllocatorType<basic_json>` |
| `pointer` | `#!cpp std::allocator_traits<allocator_type>::pointer` |
| `const_pointer` | `#!cpp std::allocator_traits<allocator_type>::const_pointer` |
| `iterator` | [LegacyBidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator) |
| `const_iterator` | constant [LegacyBidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator) |
| `reverse_iterator` | reverse iterator, derived from `iterator` |
| `const_reverse_iterator` | reverse iterator, derived from `const_iterator` |
| `iteration_proxy` | helper type for [`items`](items.md) function |
### JSON value data types
- [**array_t**](array_t.md) - type for arrays
- [**binary_t**](binary_t.md) - type for binary arrays
- [**boolean_t**](boolean_t.md) - type for booleans
- [**default_object_comparator_t**](default_object_comparator_t.md) - default comparator for objects
- [**number_float_t**](number_float_t.md) - type for numbers (floating-point)
- [**number_integer_t**](number_integer_t.md) - type for numbers (integer)
- [**number_unsigned_t**](number_unsigned_t.md) - type for numbers (unsigned)
- [**object_comparator_t**](object_comparator_t.md) - comparator for objects
- [**object_t**](object_t.md) - type for objects
- [**string_t**](string_t.md) - type for strings
### Parser callback
- [**parse_event_t**](parse_event_t.md) - parser event types
- [**parser_callback_t**](parser_callback_t.md) - per-element parser callback type
## Member functions
- [(constructor)](basic_json.md)
- [(destructor)](~basic_json.md)
- [**operator=**](operator=.md) - copy assignment
- [**array**](array.md) (_static_) - explicitly create an array
- [**binary**](binary.md) (_static_) - explicitly create a binary array
- [**object**](object.md) (_static_) - explicitly create an object
### Object inspection
Functions to inspect the type of a JSON value.
- [**type**](type.md) - return the type of the JSON value
- [**operator value_t**](operator_value_t.md) - return the type of the JSON value
- [**type_name**](type_name.md) - return the type as string
- [**is_primitive**](is_primitive.md) - return whether the type is primitive
- [**is_structured**](is_structured.md) - return whether the type is structured
- [**is_null**](is_null.md) - return whether the value is null
- [**is_boolean**](is_boolean.md) - return whether the value is a boolean
- [**is_number**](is_number.md) - return whether the value is a number
- [**is_number_integer**](is_number_integer.md) - return whether the value is an integer number
- [**is_number_unsigned**](is_number_unsigned.md) - return whether the value is an unsigned integer number
- [**is_number_float**](is_number_float.md) - return whether the value is a floating-point number
- [**is_object**](is_object.md) - return whether the value is an object
- [**is_array**](is_array.md) - return whether the value is an array
- [**is_string**](is_string.md) - return whether the value is a string
- [**is_binary**](is_binary.md) - return whether the value is a binary array
- [**is_discarded**](is_discarded.md) - return whether the value is discarded
Optional functions to access the [diagnostic positions](../macros/json_diagnostic_positions.md).
- [**start_pos**](start_pos.md) - return the start position of the value
- [**end_pos**](end_pos.md) - return the one past the end position of the value
### Value access
Direct access to the stored value of a JSON value.
- [**get**](get.md) - get a value
- [**get_to**](get_to.md) - get a value and write it to a destination
- [**get_ptr**](get_ptr.md) - get a pointer value
- [**get_ref**](get_ref.md) - get a reference value
- [**operator ValueType**](operator_ValueType.md) - get a value
- [**get_binary**](get_binary.md) - get a binary value
### Element access
Access to the JSON value
- [**at**](at.md) - access specified element with bounds checking
- [**operator[]**](operator[].md) - access specified element
- [**value**](value.md) - access specified object element with default value
- [**front**](front.md) - access the first element
- [**back**](back.md) - access the last element
### Lookup
- [**find**](find.md) - find an element in a JSON object
- [**count**](count.md) - returns the number of occurrences of a key in a JSON object
- [**contains**](contains.md) - check the existence of an element in a JSON object
### Iterators
- [**begin**](begin.md) - returns an iterator to the first element
- [**cbegin**](cbegin.md) - returns a const iterator to the first element
- [**end**](end.md) - returns an iterator to one past the last element
- [**cend**](cend.md) - returns a const iterator to one past the last element
- [**rbegin**](rbegin.md) - returns an iterator to the reverse-beginning
- [**rend**](rend.md) - returns an iterator to the reverse-end
- [**crbegin**](crbegin.md) - returns a const iterator to the reverse-beginning
- [**crend**](crend.md) - returns a const iterator to the reverse-end
- [**items**](items.md) - wrapper to access iterator member functions in range-based for
### Capacity
- [**empty**](empty.md) - checks whether the container is empty
- [**size**](size.md) - returns the number of elements
- [**max_size**](max_size.md) - returns the maximum possible number of elements
### Modifiers
- [**clear**](clear.md) - clears the contents
- [**push_back**](push_back.md) - add a value to an array/object
- [**operator+=**](operator+=.md) - add a value to an array/object
- [**emplace_back**](emplace_back.md) - add a value to an array
- [**emplace**](emplace.md) - add a value to an object if a key does not exist
- [**erase**](erase.md) - remove elements
- [**insert**](insert.md) - inserts elements
- [**update**](update.md) - updates a JSON object from another object, overwriting existing keys
- [**swap**](swap.md) - exchanges the values
### Lexicographical comparison operators
- [**operator==**](operator_eq.md) - comparison: equal
- [**operator!=**](operator_ne.md) - comparison: not equal
- [**operator<**](operator_lt.md) - comparison: less than
- [**operator>**](operator_gt.md) - comparison: greater than
- [**operator<=**](operator_le.md) - comparison: less than or equal
- [**operator>=**](operator_ge.md) - comparison: greater than or equal
- [**operator<=>**](operator_spaceship.md) - comparison: 3-way
### Serialization / Dumping
- [**dump**](dump.md) - serialization
### Deserialization / Parsing
- [**parse**](parse.md) (_static_) - deserialize from a compatible input
- [**accept**](accept.md) (_static_) - check if the input is valid JSON
- [**sax_parse**](sax_parse.md) (_static_) - generate SAX events
### JSON Pointer functions
- [**flatten**](flatten.md) - return flattened JSON value
- [**unflatten**](unflatten.md) - unflatten a previously flattened JSON value
### JSON Patch functions
- [**patch**](patch.md) - applies a JSON patch
- [**patch_inplace**](patch_inplace.md) - applies a JSON patch in place
- [**diff**](diff.md) (_static_) - creates a diff as a JSON patch
### JSON Merge Patch functions
- [**merge_patch**](merge_patch.md) - applies a JSON Merge Patch
## Static functions
- [**meta**](meta.md) - returns version information on the library
- [**get_allocator**](get_allocator.md) - returns the allocator associated with the container
### Binary formats
- [**from_bjdata**](from_bjdata.md) (_static_) - create a JSON value from an input in BJData format
- [**from_bson**](from_bson.md) (_static_) - create a JSON value from an input in BSON format
- [**from_cbor**](from_cbor.md) (_static_) - create a JSON value from an input in CBOR format
- [**from_msgpack**](from_msgpack.md) (_static_) - create a JSON value from an input in MessagePack format
- [**from_ubjson**](from_ubjson.md) (_static_) - create a JSON value from an input in UBJSON format
- [**to_bjdata**](to_bjdata.md) (_static_) - create a BJData serialization of a given JSON value
- [**to_bson**](to_bson.md) (_static_) - create a BSON serialization of a given JSON value
- [**to_cbor**](to_cbor.md) (_static_) - create a CBOR serialization of a given JSON value
- [**to_msgpack**](to_msgpack.md) (_static_) - create a MessagePack serialization of a given JSON value
- [**to_ubjson**](to_ubjson.md) (_static_) - create a UBJSON serialization of a given JSON value
## Non-member functions
- [**operator<<(std::ostream&)**](../operator_ltlt.md) - serialize to stream
- [**operator>>(std::istream&)**](../operator_gtgt.md) - deserialize from stream
- [**to_string**](to_string.md) - user-defined `to_string` function for JSON values
- [**format_as**](format_as.md) - user-defined `format_as` function for JSON values (fmt support)
## Literals
- [**operator""_json**](../operator_literal_json.md) - user-defined string literal for JSON values
## Helper classes
- [**std::formatter&lt;basic_json&gt;**](std_formatter.md) - make JSON values formattable with `std::format`
- [**std::hash&lt;basic_json&gt;**](std_hash.md) - return a hash value for a JSON object
- [**std::swap&lt;basic_json&gt;**](std_swap.md) - exchanges the values of two JSON objects
## Examples
??? example
The example shows how the library is used.
```cpp
--8<-- "examples/README.cpp"
```
Output:
```json
--8<-- "examples/README.output"
```
## See also
- [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format](https://tools.ietf.org/html/rfc8259)
## Version history
- Added in version 1.0.0.
-131
View File
@@ -1,131 +0,0 @@
# <small>nlohmann::basic_json::</small>accept
```cpp
// (1)
template<typename InputType>
static bool accept(InputType&& i,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
// (2)
template<typename IteratorType, typename SentinelType = IteratorType>
static bool accept(IteratorType first, SentinelType last,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
```
Checks whether the input is valid JSON.
1. Reads from a compatible input.
2. Reads from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted
respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to
the iterator type with `operator!=`.
Unlike the [`parse()`](parse.md) function, this function neither throws an exception in case of invalid JSON input
(i.e., a parse error) nor creates diagnostic information.
## Template parameters
`InputType`
: A compatible input, for instance:
- an `std::istream` object
- a `#!c FILE` pointer (throws if null)
- a C-style array of characters
- a pointer to a null-terminated string of single byte characters (throws if null)
- a `std::string`
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
`IteratorType`
: a compatible iterator type, for instance.
- a pair of `std::string::iterator` or `std::vector<std::uint8_t>::iterator`
- a pair of pointers such as `ptr` and `ptr + len`
`SentinelType`
: defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
- a custom sentinel type for C++20 ranges
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
## Parameters
`i` (in)
: Input to parse from.
`ignore_comments` (in)
: whether comments should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default)
`ignore_trailing_commas` (in)
: whether trailing commas in arrays or objects should be ignored and treated like whitespace (`#!cpp true`) or yield a parse error
(`#!cpp false`); (optional, `#!cpp false` by default)
`first` (in)
: iterator to the start of the character range
`last` (in)
: iterator to the end of the character range, or a sentinel value that compares equal to the end iterator with `operator!=`
## Return value
Whether the input is valid JSON.
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Exceptions
Throws [`parse_error.101`](../../home/exceptions.md#jsonexceptionparse_error101) in case of an empty input like a null `#!c FILE*` or `#!c char*` pointer.
## Complexity
Linear in the length of the input. The parser is a predictive LL(1) parser.
## Notes
A UTF-8 byte order mark is silently ignored.
## Examples
??? example
The example below demonstrates the `accept()` function reading from a string.
```cpp
--8<-- "examples/accept__string.cpp"
```
Output:
```json
--8<-- "examples/accept__string.output"
```
## See also
- [parse](parse.md) - deserialize from a compatible input
- [sax_parse](sax_parse.md) - parse input using the SAX interface
- [operator>>](../operator_gtgt.md) - deserialize from stream
## Version history
- Added in version 3.0.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0.
- Changed [runtime assertion](../../features/assertions.md) in case of `FILE*` null pointers to exception in version 3.12.0.
- Added `ignore_trailing_commas` in version 3.13.0.
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
!!! warning "Deprecation"
Overload (2) replaces calls to `accept` with a pair of iterators as their first parameter which has been
deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like
`#!cpp accept({ptr, ptr+len}, ...);` with `#!cpp accept(ptr, ptr+len, ...);`.
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated
function.
File diff suppressed because one or more lines are too long
-147
View File
@@ -1,147 +0,0 @@
# nlohmann::basic_json::accept
```
// (1)
template<typename InputType>
static bool accept(InputType&& i,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
// (2)
template<typename IteratorType, typename SentinelType = IteratorType>
static bool accept(IteratorType first, SentinelType last,
const bool ignore_comments = false,
const bool ignore_trailing_commas = false);
```
Checks whether the input is valid JSON.
1. Reads from a compatible input.
1. Reads from a pair of character iterators, or an iterator and a sentinel of a different type (C++20 ranges support)
The value_type of the iterator must be an integral type with a size of 1, 2, or 4 bytes, which will be interpreted respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to the iterator type with `operator!=`.
Unlike the [`parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md) function, this function neither throws an exception in case of invalid JSON input (i.e., a parse error) nor creates diagnostic information.
## Template parameters
`InputType` : A compatible input, for instance:
```
- an `std::istream` object
- a `FILE` pointer (throws if null)
- a C-style array of characters
- a pointer to a null-terminated string of single byte characters (throws if null)
- a `std::string`
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
```
`IteratorType` : a compatible iterator type, for instance.
```
- a pair of `std::string::iterator` or `std::vector<std::uint8_t>::iterator`
- a pair of pointers such as `ptr` and `ptr + len`
```
`SentinelType` : defaults to `IteratorType`; may be a different type comparable to `IteratorType` via `operator!=`, for instance.
```
- a custom sentinel type for C++20 ranges
- `std::default_sentinel_t`, when `IteratorType` is `std::counted_iterator`
```
## Parameters
`i` (in) : Input to parse from.
`ignore_comments` (in) : whether comments should be ignored and treated like whitespace (`true`) or yield a parse error (`false`); (optional, `false` by default)
`ignore_trailing_commas` (in) : whether trailing commas in arrays or objects should be ignored and treated like whitespace (`true`) or yield a parse error (`false`); (optional, `false` by default)
`first` (in) : iterator to the start of the character range
`last` (in) : iterator to the end of the character range, or a sentinel value that compares equal to the end iterator with `operator!=`
## Return value
Whether the input is valid JSON.
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Exceptions
Throws [`parse_error.101`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error101) in case of an empty input like a null `FILE*` or `char*` pointer.
## Complexity
Linear in the length of the input. The parser is a predictive LL(1) parser.
## Notes
A UTF-8 byte order mark is silently ignored.
## Examples
Example
The example below demonstrates the `accept()` function reading from a string.
```
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// a valid JSON text
auto valid_text = R"(
{
"numbers": [1, 2, 3]
}
)";
// an invalid JSON text
auto invalid_text = R"(
{
"strings": ["extra", "comma", ]
}
)";
std::cout << std::boolalpha
<< json::accept(valid_text) << ' '
<< json::accept(invalid_text) << '\n';
}
```
Output:
```
true false
```
## See also
- [parse](https://json.nlohmann.me/api/basic_json/parse/index.md) - deserialize from a compatible input
- [sax_parse](https://json.nlohmann.me/api/basic_json/sax_parse/index.md) - parse input using the SAX interface
- [operator>>](https://json.nlohmann.me/api/operator_gtgt/index.md) - deserialize from stream
## Version history
- Added in version 3.0.0.
- Ignoring comments via `ignore_comments` added in version 3.9.0.
- Changed [runtime assertion](https://json.nlohmann.me/features/assertions/index.md) in case of `FILE*` null pointers to exception in version 3.12.0.
- Added `ignore_trailing_commas` in version 3.13.0.
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0.
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0.
Deprecation
Overload (2) replaces calls to `accept` with a pair of iterators as their first parameter which has been deprecated in version 3.8.0. This overload will be removed in version 4.0.0. Please replace all calls like `accept({ptr, ptr+len}, ...);` with `accept(ptr, ptr+len, ...);`.
You should be warned by your compiler with a `-Wdeprecated-declarations` warning if you are using a deprecated function.
-61
View File
@@ -1,61 +0,0 @@
# <small>nlohmann::basic_json::</small>array
```cpp
static basic_json array(initializer_list_t init = {});
```
Creates a JSON array value from a given initializer list. That is, given a list of values `a, b, c`, creates the JSON
value `#!json [a, b, c]`. If the initializer list is empty, the empty array `#!json []` is created.
## Parameters
`init` (in)
: initializer list with JSON values to create an array from (optional)
## Return value
JSON array value
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Complexity
Linear in the size of `init`.
## Notes
This function is only needed to express two edge cases that cannot be realized with the initializer list constructor
([`basic_json(initializer_list_t, bool, value_t)`](basic_json.md)). These cases are:
1. creating an array whose elements are all pairs whose first element is a string -- in this case, the initializer list
constructor would create an object, taking the first elements as keys
2. creating an empty array -- passing the empty initializer list to the initializer list constructor yields an empty
object
## Examples
??? example
The following code shows an example for the `array` function.
```cpp
--8<-- "examples/array.cpp"
```
Output:
```json
--8<-- "examples/array.output"
```
## See also
- [`basic_json(initializer_list_t)`](basic_json.md) - create a JSON value from an initializer list
- [`object`](object.md) - create a JSON object value from an initializer list
- [Creating JSON values](../../features/creating_values.md) - the article on creating JSON values
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-77
View File
@@ -1,77 +0,0 @@
# nlohmann::basic_json::array
```
static basic_json array(initializer_list_t init = {});
```
Creates a JSON array value from a given initializer list. That is, given a list of values `a, b, c`, creates the JSON value `[a, b, c]`. If the initializer list is empty, the empty array `[]` is created.
## Parameters
`init` (in) : initializer list with JSON values to create an array from (optional)
## Return value
JSON array value
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Complexity
Linear in the size of `init`.
## Notes
This function is only needed to express two edge cases that cannot be realized with the initializer list constructor ([`basic_json(initializer_list_t, bool, value_t)`](https://json.nlohmann.me/api/basic_json/basic_json/index.md)). These cases are:
1. creating an array whose elements are all pairs whose first element is a string -- in this case, the initializer list constructor would create an object, taking the first elements as keys
1. creating an empty array -- passing the empty initializer list to the initializer list constructor yields an empty object
## Examples
Example
The following code shows an example for the `array` function.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON arrays
json j_no_init_list = json::array();
json j_empty_init_list = json::array({});
json j_nonempty_init_list = json::array({1, 2, 3, 4});
json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} });
// serialize the JSON arrays
std::cout << j_no_init_list << '\n';
std::cout << j_empty_init_list << '\n';
std::cout << j_nonempty_init_list << '\n';
std::cout << j_list_of_pairs << '\n';
}
```
Output:
```
[]
[]
[1,2,3,4]
[["one",1],["two",2]]
```
## See also
- [`basic_json(initializer_list_t)`](https://json.nlohmann.me/api/basic_json/basic_json/index.md) - create a JSON value from an initializer list
- [`object`](https://json.nlohmann.me/api/basic_json/object/index.md) - create a JSON object value from an initializer list
- [Creating JSON values](https://json.nlohmann.me/features/creating_values/index.md) - the article on creating JSON values
## Version history
- Added in version 1.0.0.
-68
View File
@@ -1,68 +0,0 @@
# <small>nlohmann::basic_json::</small>array_t
```cpp
using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
```
The type used to store JSON arrays.
[RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON arrays as follows:
> An array is an ordered sequence of zero or more values.
To store objects in C++, a type is defined by the template parameters explained below.
## Template parameters
`ArrayType`
: container type to store arrays (e.g., `std::vector` or `std::list`)
`AllocatorType`
: the allocator to use for objects (e.g., `std::allocator`)
## Notes
#### Default type
With the default values for `ArrayType` (`std::vector`) and `AllocatorType` (`std::allocator`), the default value for
`array_t` is:
```cpp
std::vector<
basic_json, // value_type
std::allocator<basic_json> // allocator_type
>
```
#### Limits
[RFC 8259](https://tools.ietf.org/html/rfc8259) specifies:
> An implementation may set limits on the maximum depth of nesting.
In this class, the array's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be
introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the
[`max_size`](max_size.md) function of a JSON array.
#### Storage
Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of type
`#!cpp array_t*` must be dereferenced.
## Examples
??? example
The following code shows that `array_t` is by default, a typedef to `#!cpp std::vector<nlohmann::json>`.
```cpp
--8<-- "examples/array_t.cpp"
```
Output:
```json
--8<-- "examples/array_t.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-73
View File
@@ -1,73 +0,0 @@
# nlohmann::basic_json::array_t
```
using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
```
The type used to store JSON arrays.
[RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON arrays as follows:
> An array is an ordered sequence of zero or more values.
To store objects in C++, a type is defined by the template parameters explained below.
## Template parameters
`ArrayType` : container type to store arrays (e.g., `std::vector` or `std::list`)
`AllocatorType` : the allocator to use for objects (e.g., `std::allocator`)
## Notes
#### Default type
With the default values for `ArrayType` (`std::vector`) and `AllocatorType` (`std::allocator`), the default value for `array_t` is:
```
std::vector<
basic_json, // value_type
std::allocator<basic_json> // allocator_type
>
```
#### Limits
[RFC 8259](https://tools.ietf.org/html/rfc8259) specifies:
> An implementation may set limits on the maximum depth of nesting.
In this class, the array's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the [`max_size`](https://json.nlohmann.me/api/basic_json/max_size/index.md) function of a JSON array.
#### Storage
Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of type `array_t*` must be dereferenced.
## Examples
Example
The following code shows that `array_t` is by default, a typedef to `std::vector<nlohmann::json>`.
```
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::cout << std::boolalpha << std::is_same<std::vector<json>, json::array_t>::value << std::endl;
}
```
Output:
```
true
```
## Version history
- Added in version 1.0.0.
-228
View File
@@ -1,228 +0,0 @@
# <small>nlohmann::basic_json::</small>at
```cpp
// (1)
reference at(size_type idx);
const_reference at(size_type idx) const;
// (2)
reference at(const typename object_t::key_type& key);
const_reference at(const typename object_t::key_type& key) const;
// (3)
template<typename KeyType>
reference at(KeyType&& key);
template<typename KeyType>
const_reference at(KeyType&& key) const;
// (4)
reference at(const json_pointer& ptr);
const_reference at(const json_pointer& ptr) const;
```
1. Returns a reference to the array element at specified location `idx`, with bounds checking.
2. Returns a reference to the object element with specified key `key`, with bounds checking.
3. See 2. This overload is only available if `KeyType` is comparable with `#!cpp typename object_t::key_type` and
`#!cpp typename object_comparator_t::is_transparent` denotes a type.
4. Returns a reference to the element at specified JSON pointer `ptr`, with bounds checking.
## Template parameters
`KeyType`
: A type for an object key other than [`json_pointer`](../json_pointer/index.md) that is comparable with
[`string_t`](string_t.md) using [`object_comparator_t`](object_comparator_t.md).
This can also be a string view (C++17).
## Parameters
`idx` (in)
: index of the element to access
`key` (in)
: object key of the elements to access
`ptr` (in)
: JSON pointer to the desired element
## Return value
1. reference to the element at index `idx`
2. reference to the element at key `key`
3. reference to the element at key `key`
4. reference to the element pointed to by `ptr`
## Exception safety
Strong exception safety: if an exception occurs, the original value stays intact.
## Exceptions
1. The function can throw the following exceptions:
- Throws [`type_error.304`](../../home/exceptions.md#jsonexceptiontype_error304) if the JSON value is not an array;
in this case, calling `at` with an index makes no sense. See the example below.
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) if the index `idx` is out of
range of the array; that is, `idx >= size()`. See the example below.
2. The function can throw the following exceptions:
- Throws [`type_error.304`](../../home/exceptions.md#jsonexceptiontype_error304) if the JSON value is not an object;
in this case, calling `at` with a key makes no sense. See the example below.
- Throws [`out_of_range.403`](../../home/exceptions.md#jsonexceptionout_of_range403) if the key `key` is not
stored in the object; that is, `find(key) == end()`. See the example below.
3. See 2.
4. The function can throw the following exceptions:
- Throws [`parse_error.106`](../../home/exceptions.md#jsonexceptionparse_error106) if an array index in the passed
JSON pointer `ptr` begins with '0'. See the example below.
- Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) if an array index in the passed
JSON pointer `ptr` is not a number. See the example below.
- Throws [`out_of_range.401`](../../home/exceptions.md#jsonexceptionout_of_range401) if an array index in the passed
JSON pointer `ptr` is out of range. See the example below.
- Throws [`out_of_range.402`](../../home/exceptions.md#jsonexceptionout_of_range402) if the array index '-' is used
in the passed JSON pointer `ptr`. As `at` provides checked access (and no elements are implicitly inserted), the
index '-' is always invalid. See the example below.
- Throws [`out_of_range.403`](../../home/exceptions.md#jsonexceptionout_of_range403) if the JSON pointer describes a
key of an object which cannot be found. See the example below.
- Throws [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) if the JSON pointer `ptr` can
not be resolved. See the example below.
- Throws [`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) if an array index in the passed
JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
## Complexity
1. Constant.
2. Logarithmic in the size of the container.
3. Logarithmic in the size of the container.
4. Logarithmic in the size of the container.
## Examples
??? example "Example: (1) access specified array element with bounds checking"
The example below shows how array elements can be read and written using `at()`. It also demonstrates the different
exceptions that can be thrown.
```cpp
--8<-- "examples/at__size_type.cpp"
```
Output:
```json
--8<-- "examples/at__size_type.output"
```
??? example "Example: (1) access specified array element with bounds checking"
The example below shows how array elements can be read using `at()`. It also demonstrates the different exceptions
that can be thrown.
```cpp
--8<-- "examples/at__size_type_const.cpp"
```
Output:
```json
--8<-- "examples/at__size_type_const.output"
```
??? example "Example: (2) access specified object element with bounds checking"
The example below shows how object elements can be read and written using `at()`. It also demonstrates the different
exceptions that can be thrown.
```cpp
--8<-- "examples/at__object_t_key_type.cpp"
```
Output:
```json
--8<-- "examples/at__object_t_key_type.output"
```
??? example "Example: (2) access specified object element with bounds checking"
The example below shows how object elements can be read using `at()`. It also demonstrates the different exceptions
that can be thrown.
```cpp
--8<-- "examples/at__object_t_key_type_const.cpp"
```
Output:
```json
--8<-- "examples/at__object_t_key_type_const.output"
```
??? example "Example: (3) access specified object element using string_view with bounds checking"
The example below shows how object elements can be read and written using `at()`. It also demonstrates the different
exceptions that can be thrown.
```cpp
--8<-- "examples/at__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/at__keytype.c++17.output"
```
??? example "Example: (3) access specified object element using string_view with bounds checking"
The example below shows how object elements can be read using `at()`. It also demonstrates the different exceptions
that can be thrown.
```cpp
--8<-- "examples/at__keytype_const.c++17.cpp"
```
Output:
```json
--8<-- "examples/at__keytype_const.c++17.output"
```
??? example "Example: (4) access specified element via JSON Pointer"
The example below shows how object elements can be read and written using `at()`. It also demonstrates the different
exceptions that can be thrown.
```cpp
--8<-- "examples/at__json_pointer.cpp"
```
Output:
```json
--8<-- "examples/at__json_pointer.output"
```
??? example "Example: (4) access specified element via JSON Pointer"
The example below shows how object elements can be read using `at()`. It also demonstrates the different exceptions
that can be thrown.
```cpp
--8<-- "examples/at__json_pointer_const.cpp"
```
Output:
```json
--8<-- "examples/at__json_pointer_const.output"
```
## See also
- documentation on [checked access](../../features/element_access/checked_access.md)
- [`operator[]`](operator%5B%5D.md) for unchecked access by reference
- [`value`](value.md) for access with default value
## Version history
1. Added in version 1.0.0.
2. Added in version 1.0.0.
3. Added in version 3.11.0.
4. Added in version 2.0.0.
File diff suppressed because one or more lines are too long
-668
View File
@@ -1,668 +0,0 @@
# nlohmann::basic_json::at
```
// (1)
reference at(size_type idx);
const_reference at(size_type idx) const;
// (2)
reference at(const typename object_t::key_type& key);
const_reference at(const typename object_t::key_type& key) const;
// (3)
template<typename KeyType>
reference at(KeyType&& key);
template<typename KeyType>
const_reference at(KeyType&& key) const;
// (4)
reference at(const json_pointer& ptr);
const_reference at(const json_pointer& ptr) const;
```
1. Returns a reference to the array element at specified location `idx`, with bounds checking.
1. Returns a reference to the object element with specified key `key`, with bounds checking.
1. See 2. This overload is only available if `KeyType` is comparable with `typename object_t::key_type` and `typename object_comparator_t::is_transparent` denotes a type.
1. Returns a reference to the element at specified JSON pointer `ptr`, with bounds checking.
## Template parameters
`KeyType` : A type for an object key other than [`json_pointer`](https://json.nlohmann.me/api/json_pointer/index.md) that is comparable with [`string_t`](https://json.nlohmann.me/api/basic_json/string_t/index.md) using [`object_comparator_t`](https://json.nlohmann.me/api/basic_json/object_comparator_t/index.md). This can also be a string view (C++17).
## Parameters
`idx` (in) : index of the element to access
`key` (in) : object key of the elements to access
`ptr` (in) : JSON pointer to the desired element
## Return value
1. reference to the element at index `idx`
1. reference to the element at key `key`
1. reference to the element at key `key`
1. reference to the element pointed to by `ptr`
## Exception safety
Strong exception safety: if an exception occurs, the original value stays intact.
## Exceptions
1. The function can throw the following exceptions:
- Throws [`type_error.304`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error304) if the JSON value is not an array; in this case, calling `at` with an index makes no sense. See the example below.
- Throws [`out_of_range.401`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range401) if the index `idx` is out of range of the array; that is, `idx >= size()`. See the example below.
1. The function can throw the following exceptions:
- Throws [`type_error.304`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error304) if the JSON value is not an object; in this case, calling `at` with a key makes no sense. See the example below.
- Throws [`out_of_range.403`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range403) if the key `key` is not stored in the object; that is, `find(key) == end()`. See the example below.
1. See 2.
1. The function can throw the following exceptions:
- Throws [`parse_error.106`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error106) if an array index in the passed JSON pointer `ptr` begins with '0'. See the example below.
- Throws [`parse_error.109`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error109) if an array index in the passed JSON pointer `ptr` is not a number. See the example below.
- Throws [`out_of_range.401`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range401) if an array index in the passed JSON pointer `ptr` is out of range. See the example below.
- Throws [`out_of_range.402`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range402) if the array index '-' is used in the passed JSON pointer `ptr`. As `at` provides checked access (and no elements are implicitly inserted), the index '-' is always invalid. See the example below.
- Throws [`out_of_range.403`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range403) if the JSON pointer describes a key of an object which cannot be found. See the example below.
- Throws [`out_of_range.404`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range404) if the JSON pointer `ptr` can not be resolved. See the example below.
- Throws [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) if an array index in the passed JSON pointer `ptr` exceeds the range of `size_type` (e.g., on 32-bit platforms).
## Complexity
1. Constant.
1. Logarithmic in the size of the container.
1. Logarithmic in the size of the container.
1. Logarithmic in the size of the container.
## Examples
Example: (1) access specified array element with bounds checking
The example below shows how array elements can be read and written using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON array
json array = {"first", "2nd", "third", "fourth"};
// output element at index 2 (third element)
std::cout << array.at(2) << '\n';
// change element at index 1 (second element) to "second"
array.at(1) = "second";
// output changed array
std::cout << array << '\n';
// exception type_error.304
try
{
// use at() on a non-array type
json str = "I am a string";
str.at(0) = "Another string";
}
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
// exception out_of_range.401
try
{
// try to write beyond the array limit
array.at(5) = "sixth";
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
"third"
["first","second","third","fourth"]
[json.exception.type_error.304] cannot use at() with string
[json.exception.out_of_range.401] array index 5 is out of range
```
Example: (1) access specified array element with bounds checking
The example below shows how array elements can be read using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON array
const json array = {"first", "2nd", "third", "fourth"};
// output element at index 2 (third element)
std::cout << array.at(2) << '\n';
// exception type_error.304
try
{
// use at() on a non-array type
const json str = "I am a string";
std::cout << str.at(0) << '\n';
}
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
// exception out_of_range.401
try
{
// try to read beyond the array limit
std::cout << array.at(5) << '\n';
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
"third"
[json.exception.type_error.304] cannot use at() with string
[json.exception.out_of_range.401] array index 5 is out of range
```
Example: (2) access specified object element with bounds checking
The example below shows how object elements can be read and written using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON object
json object =
{
{"the good", "il buono"},
{"the bad", "il cattivo"},
{"the ugly", "il brutto"}
};
// output element with key "the ugly"
std::cout << object.at("the ugly") << '\n';
// change element with key "the bad"
object.at("the bad") = "il cattivo";
// output changed array
std::cout << object << '\n';
// exception type_error.304
try
{
// use at() on a non-object type
json str = "I am a string";
str.at("the good") = "Another string";
}
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
// exception out_of_range.401
try
{
// try to write at a nonexisting key
object.at("the fast") = "il rapido";
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
"il brutto"
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
[json.exception.type_error.304] cannot use at() with string
[json.exception.out_of_range.403] key 'the fast' not found
```
Example: (2) access specified object element with bounds checking
The example below shows how object elements can be read using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON object
const json object =
{
{"the good", "il buono"},
{"the bad", "il cattivo"},
{"the ugly", "il brutto"}
};
// output element with key "the ugly"
std::cout << object.at("the ugly") << '\n';
// exception type_error.304
try
{
// use at() on a non-object type
const json str = "I am a string";
std::cout << str.at("the good") << '\n';
}
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
// exception out_of_range.401
try
{
// try to read from a nonexisting key
std::cout << object.at("the fast") << '\n';
}
catch (const json::out_of_range)
{
std::cout << "out of range" << '\n';
}
}
```
Output:
```
"il brutto"
[json.exception.type_error.304] cannot use at() with string
out of range
```
Example: (3) access specified object element using string_view with bounds checking
The example below shows how object elements can be read and written using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <string_view>
#include <nlohmann/json.hpp>
using namespace std::string_view_literals;
using json = nlohmann::json;
int main()
{
// create JSON object
json object =
{
{"the good", "il buono"},
{"the bad", "il cattivo"},
{"the ugly", "il brutto"}
};
// output element with key "the ugly" using string_view
std::cout << object.at("the ugly"sv) << '\n';
// change element with key "the bad" using string_view
object.at("the bad"sv) = "il cattivo";
// output changed array
std::cout << object << '\n';
// exception type_error.304
try
{
// use at() with string_view on a non-object type
json str = "I am a string";
str.at("the good"sv) = "Another string";
}
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
// exception out_of_range.401
try
{
// try to write at a nonexisting key using string_view
object.at("the fast"sv) = "il rapido";
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
"il brutto"
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
[json.exception.type_error.304] cannot use at() with string
[json.exception.out_of_range.403] key 'the fast' not found
```
Example: (3) access specified object element using string_view with bounds checking
The example below shows how object elements can be read using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <string_view>
#include <nlohmann/json.hpp>
using namespace std::string_view_literals;
using json = nlohmann::json;
int main()
{
// create JSON object
const json object =
{
{"the good", "il buono"},
{"the bad", "il cattivo"},
{"the ugly", "il brutto"}
};
// output element with key "the ugly" using string_view
std::cout << object.at("the ugly"sv) << '\n';
// exception type_error.304
try
{
// use at() with string_view on a non-object type
const json str = "I am a string";
std::cout << str.at("the good"sv) << '\n';
}
catch (const json::type_error& e)
{
std::cout << e.what() << '\n';
}
// exception out_of_range.401
try
{
// try to read from a nonexisting key using string_view
std::cout << object.at("the fast"sv) << '\n';
}
catch (const json::out_of_range& e)
{
std::cout << "out of range" << '\n';
}
}
```
Output:
```
"il brutto"
[json.exception.type_error.304] cannot use at() with string
out of range
```
Example: (4) access specified element via JSON Pointer
The example below shows how object elements can be read and written using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace nlohmann::literals;
int main()
{
// create a JSON value
json j =
{
{"number", 1}, {"string", "foo"}, {"array", {1, 2}}
};
// read-only access
// output element with JSON pointer "/number"
std::cout << j.at("/number"_json_pointer) << '\n';
// output element with JSON pointer "/string"
std::cout << j.at("/string"_json_pointer) << '\n';
// output element with JSON pointer "/array"
std::cout << j.at("/array"_json_pointer) << '\n';
// output element with JSON pointer "/array/1"
std::cout << j.at("/array/1"_json_pointer) << '\n';
// writing access
// change the string
j.at("/string"_json_pointer) = "bar";
// output the changed string
std::cout << j["string"] << '\n';
// change an array element
j.at("/array/1"_json_pointer) = 21;
// output the changed array
std::cout << j["array"] << '\n';
// out_of_range.106
try
{
// try to use an array index with leading '0'
json::reference ref = j.at("/array/01"_json_pointer);
}
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.109
try
{
// try to use an array index that is not a number
json::reference ref = j.at("/array/one"_json_pointer);
}
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.401
try
{
// try to use an invalid array index
json::reference ref = j.at("/array/4"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.402
try
{
// try to use the array index '-'
json::reference ref = j.at("/array/-"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.403
try
{
// try to use a JSON pointer to a nonexistent object key
json::const_reference ref = j.at("/foo"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.404
try
{
// try to use a JSON pointer that cannot be resolved
json::reference ref = j.at("/number/foo"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
1
"foo"
[1,2]
2
"bar"
[1,21]
[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'
[json.exception.parse_error.109] parse error: array index 'one' is not a number
[json.exception.out_of_range.401] array index 4 is out of range
[json.exception.out_of_range.402] array index '-' (2) is out of range
[json.exception.out_of_range.403] key 'foo' not found
[json.exception.out_of_range.404] unresolved reference token 'foo'
```
Example: (4) access specified element via JSON Pointer
The example below shows how object elements can be read using `at()`. It also demonstrates the different exceptions that can be thrown.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace nlohmann::literals;
int main()
{
// create a JSON value
const json j =
{
{"number", 1}, {"string", "foo"}, {"array", {1, 2}}
};
// read-only access
// output element with JSON pointer "/number"
std::cout << j.at("/number"_json_pointer) << '\n';
// output element with JSON pointer "/string"
std::cout << j.at("/string"_json_pointer) << '\n';
// output element with JSON pointer "/array"
std::cout << j.at("/array"_json_pointer) << '\n';
// output element with JSON pointer "/array/1"
std::cout << j.at("/array/1"_json_pointer) << '\n';
// out_of_range.109
try
{
// try to use an array index that is not a number
json::const_reference ref = j.at("/array/one"_json_pointer);
}
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.401
try
{
// try to use an invalid array index
json::const_reference ref = j.at("/array/4"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.402
try
{
// try to use the array index '-'
json::const_reference ref = j.at("/array/-"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.403
try
{
// try to use a JSON pointer to a nonexistent object key
json::const_reference ref = j.at("/foo"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.404
try
{
// try to use a JSON pointer that cannot be resolved
json::const_reference ref = j.at("/number/foo"_json_pointer);
}
catch (const json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
1
"foo"
[1,2]
2
[json.exception.parse_error.109] parse error: array index 'one' is not a number
[json.exception.out_of_range.401] array index 4 is out of range
[json.exception.out_of_range.402] array index '-' (2) is out of range
[json.exception.out_of_range.403] key 'foo' not found
[json.exception.out_of_range.404] unresolved reference token 'foo'
```
## See also
- documentation on [checked access](https://json.nlohmann.me/features/element_access/checked_access/index.md)
- [`operator[]`](https://json.nlohmann.me/api/basic_json/operator%5B%5D/index.md) for unchecked access by reference
- [`value`](https://json.nlohmann.me/api/basic_json/value/index.md) for access with default value
## Version history
1. Added in version 1.0.0.
1. Added in version 1.0.0.
1. Added in version 3.11.0.
1. Added in version 2.0.0.
-65
View File
@@ -1,65 +0,0 @@
# <small>nlohmann::basic_json::</small>back
```cpp
reference back();
const_reference back() const;
```
Returns a reference to the last element in the container. For a JSON container `c`, the expression `c.back()` is
equivalent to
```cpp
auto tmp = c.end();
--tmp;
return *tmp;
```
## Return value
In the case of a structured type (array or object), a reference to the last element is returned. In the case of number,
string, boolean, or binary values, a reference to the value is returned.
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Exceptions
If the JSON value is `#!json null`, exception
[`invalid_iterator.214`](../../home/exceptions.md#jsonexceptioninvalid_iterator214) is thrown.
## Complexity
Constant.
## Notes
!!! info "Precondition"
The array or object must not be empty. Calling `back` on an empty array or object yields undefined behavior.
## Examples
??? example
The following code shows an example for `back()`.
```cpp
--8<-- "examples/back.cpp"
```
Output:
```json
--8<-- "examples/back.output"
```
## See also
- [front](front.md) to access the first element
## Version history
- Added in version 1.0.0.
- Adjusted code to return reference to binary values in version 3.8.0.
File diff suppressed because one or more lines are too long
-105
View File
@@ -1,105 +0,0 @@
# nlohmann::basic_json::back
```
reference back();
const_reference back() const;
```
Returns a reference to the last element in the container. For a JSON container `c`, the expression `c.back()` is equivalent to
```
auto tmp = c.end();
--tmp;
return *tmp;
```
## Return value
In the case of a structured type (array or object), a reference to the last element is returned. In the case of number, string, boolean, or binary values, a reference to the value is returned.
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Exceptions
If the JSON value is `null`, exception [`invalid_iterator.214`](https://json.nlohmann.me/home/exceptions/#jsonexceptioninvalid_iterator214) is thrown.
## Complexity
Constant.
## Notes
Precondition
The array or object must not be empty. Calling `back` on an empty array or object yields undefined behavior.
## Examples
Example
The following code shows an example for `back()`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_object_empty(json::value_t::object);
json j_array = {1, 2, 4, 8, 16};
json j_array_empty(json::value_t::array);
json j_string = "Hello, world";
// call back()
std::cout << j_boolean.back() << '\n';
std::cout << j_number_integer.back() << '\n';
std::cout << j_number_float.back() << '\n';
std::cout << j_object.back() << '\n';
//std::cout << j_object_empty.back() << '\n'; // undefined behavior
std::cout << j_array.back() << '\n';
//std::cout << j_array_empty.back() << '\n'; // undefined behavior
std::cout << j_string.back() << '\n';
// back() called on a null value
try
{
json j_null;
j_null.back();
}
catch (const json::invalid_iterator& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
true
17
23.42
2
16
"Hello, world"
[json.exception.invalid_iterator.214] cannot get value
```
## See also
- [front](https://json.nlohmann.me/api/basic_json/front/index.md) to access the first element
## Version history
- Added in version 1.0.0.
- Adjusted code to return reference to binary values in version 3.8.0.
-428
View File
@@ -1,428 +0,0 @@
# <small>nlohmann::basic_json::</small>basic_json
```cpp
// (1)
basic_json(const value_t v);
// (2)
basic_json(std::nullptr_t = nullptr) noexcept;
// (3)
template<typename CompatibleType>
basic_json(CompatibleType&& val) noexcept(noexcept(
JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
std::forward<CompatibleType>(val))));
// (4)
template<typename BasicJsonType>
basic_json(const BasicJsonType& val);
// (5)
basic_json(initializer_list_t init,
bool type_deduction = true,
value_t manual_type = value_t::array);
// (6)
basic_json(size_type cnt, const basic_json& val);
// (7)
basic_json(iterator first, iterator last);
basic_json(const_iterator first, const_iterator last);
// (8)
basic_json(const basic_json& other);
// (9)
basic_json(basic_json&& other) noexcept;
```
1. Create an empty JSON value with a given type. The value will be default initialized with an empty value which depends
on the type:
| Value type | initial value |
|------------|----------------|
| null | `#!json null` |
| boolean | `#!json false` |
| string | `#!json ""` |
| number | `#!json 0` |
| object | `#!json {}` |
| array | `#!json []` |
| binary | empty array |
The postcondition of this constructor can be restored by calling [`clear()`](clear.md).
2. Create a `#!json null` JSON value. It either takes a null pointer as parameter (explicitly creating `#!json null`)
or no parameter (implicitly creating `#!json null`). The passed null pointer itself is not read -- it is only used to
choose the right constructor.
3. This is a "catch all" constructor for all compatible JSON types; that is, types for which a `to_json()` method
exists. The constructor forwards the parameter `val` to that method (to `json_serializer<U>::to_json` method with
`U = uncvref_t<CompatibleType>`, to be exact).
Template type `CompatibleType` includes, but is not limited to, the following types:
- **arrays**: [`array_t`](array_t.md) and all kinds of compatible containers such as `std::vector`, `std::deque`,
`std::list`, `std::forward_list`, `std::array`, `std::valarray`, `std::set`, `std::unordered_set`, `std::multiset`,
and `std::unordered_multiset` with a `value_type` from which a `basic_json` value can be constructed.
- **objects**: [`object_t`](object_t.md) and all kinds of compatible associative containers such as `std::map`,
`std::unordered_map`, `std::multimap`, and `std::unordered_multimap` with a `key_type` compatible to `string_t`
and a `value_type` from which a `basic_json` value can be constructed.
- **strings**: `string_t`, string literals, and all compatible string containers can be used.
- **numbers**: [`number_integer_t`](number_integer_t.md), [`number_unsigned_t`](number_unsigned_t.md),
[`number_float_t`](number_float_t.md), and all convertible number types such as `int`, `size_t`, `int64_t`, `float`
or `double` can be used.
- **boolean**: `boolean_t` / `bool` can be used.
- **binary**: `binary_t` / `std::vector<uint8_t>` may be used; unfortunately because string literals cannot be
distinguished from binary character arrays by the C++ type system, all types compatible with `const char*` will be
directed to the string constructor instead. This is both for backwards compatibility and due to the fact that a
binary type is not a standard JSON type.
See the examples below.
4. This is a constructor for existing `basic_json` types. It does not hijack copy/move constructors, since the parameter
has different template arguments than the current ones.
The constructor tries to convert the internal `m_value` of the parameter. Each member value (object, array, string,
etc.) is serialized via the corresponding `to_json()` overload. For objects and strings, the conversion requires
that the *target* `basic_json` type's `object_t::key_type` (or `string_t`) be directly constructible from the
*source* type's corresponding member type via `is_constructible`. If this requirement is not met, the conversion
does not fail to compile; instead, it silently falls back to the array-conversion path, which represents objects
as arrays of `[key, value]` pairs and strings as arrays of character codes. This is a known limitation tracked in
[issue #3425](https://github.com/nlohmann/json/issues/3425).
5. Creates a JSON value of type array or object from the passed initializer list `init`. In case `type_deduction` is
`#!cpp true` (default), the type of the JSON value to be created is deducted from the initializer list `init`
according to the following rules:
1. If the list is empty, an empty JSON object value `{}` is created.
2. If the list consists of pairs whose first element is a string, a JSON object value is created where the first
elements of the pairs are treated as keys and the second elements are as values.
3. In all other cases, an array is created.
The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows:
1. The empty initializer list is written as `#!cpp {}` which is exactly an empty JSON object.
2. C++ has no way of describing mapped types other than to list a list of pairs. As JSON requires that keys must be
of type string, rule 2 is the weakest constraint one can pose on initializer lists to interpret them as an
object.
3. In all other cases, the initializer list could not be interpreted as a JSON object type, so interpreting it as a
JSON array type is safe.
With the rules described above, the following JSON values cannot be expressed by an initializer list:
- the empty array (`#!json []`): use `array(initializer_list_t)` with an empty initializer list in this case
- arrays whose elements satisfy rule 2: use `array(initializer_list_t)` with the same initializer list in this case
Function [`array()`](array.md) and [`object()`](object.md) force array and object creation from initializer lists,
respectively.
!!! warning "Brace initialization yields arrays"
Because this constructor takes an `initializer_list_t`, brace-initializing a `json`/`ordered_json` from
another `json` value wraps it in a single-element array rather than copying it:
```cpp
json j1 = "hello";
json j2{j1}; // [!] j2 is ["hello"], NOT a copy of j1
json j3(j1); // j3 is "hello" -- parentheses copy as expected
```
See the FAQ entry on [brace initialization](../../home/faq.md#brace-initialization-yields-arrays) for the
full explanation, an opt-in macro to change this behavior, and how to explicitly create a single-element
array (`json::array({value})`) if that is what you want.
6. Constructs a JSON array value by creating `cnt` copies of a passed value. In case `cnt` is `0`, an empty array is
created.
7. Constructs the JSON value with the contents of the range `[first, last)`. The semantics depend on the different
types a JSON value can have:
- In case of a `#!json null` type, [invalid_iterator.206](../../home/exceptions.md#jsonexceptioninvalid_iterator206)
is thrown.
- In case of other primitive types (number, boolean, or string), `first` must be `begin()` and `last` must be
`end()`. In this case, the value is copied. Otherwise,
[`invalid_iterator.204`](../../home/exceptions.md#jsonexceptioninvalid_iterator204) is thrown.
- In case of structured types (array, object), the constructor behaves as similar versions for `std::vector` or
`std::map`; that is, a JSON array or object is constructed from the values in the range.
8. Creates a copy of a given JSON value.
9. Move constructor. Constructs a JSON value with the contents of the given value `other` using move semantics. It
"steals" the resources from `other` and leaves it as JSON `#!json null` value.
## Template parameters
`CompatibleType`
: a type such that:
- `CompatibleType` is not derived from `std::istream`,
- `CompatibleType` is not `basic_json` (to avoid hijacking copy/move constructors),
- `CompatibleType` is not a different `basic_json` type (i.e. with different template arguments)
- `CompatibleType` is not a `basic_json` nested type (e.g., `json_pointer`, `iterator`, etc.)
- `json_serializer<U>` (with `U = uncvref_t<CompatibleType>`) has a `to_json(basic_json_t&, CompatibleType&&)`
method
`BasicJsonType`:
: a type such that:
- `BasicJsonType` is a `basic_json` type.
- `BasicJsonType` has different template arguments than `basic_json_t`.
**Note:** For cross-`basic_json` conversions to produce correct results, the target `basic_json`'s
`object_t::key_type` and `string_t` must be directly constructible from the source `basic_json`'s
corresponding types. See the description of overload (4) above for details on what happens when
this requirement is not met.
`U`:
: `uncvref_t<CompatibleType>`
## Parameters
`v` (in)
: the type of the value to create
`val` (in)
: the value to be forwarded to the respective constructor
`init` (in)
: initializer list with JSON values
`type_deduction` (in)
: internal parameter; when set to `#!cpp true`, the type of the JSON value is deducted from the initializer list
`init`; when set to `#!cpp false`, the type provided via `manual_type` is forced. This mode is used by the functions
`array(initializer_list_t)` and `object(initializer_list_t)`.
`manual_type` (in)
: internal parameter; when `type_deduction` is set to `#!cpp false`, the created JSON value will use the provided type
(only `value_t::array` and `value_t::object` are valid); when `type_deduction` is set to `#!cpp true`, this
parameter has no effect
`cnt` (in)
: the number of JSON copies of `val` to create
`first` (in)
: the beginning of the range to copy from (included)
`last` (in)
: the end of the range to copy from (excluded)
`other` (in)
: the JSON value to copy/move
## Exception safety
1. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
2. No-throw guarantee: this constructor never throws exceptions.
3. Depends on the called constructor. For types directly supported by the library (i.e., all types for which no
`to_json()` function was provided), a strong guarantee holds: if an exception is thrown, there are no changes to any
JSON value.
4. Depends on the called constructor. For types directly supported by the library (i.e., all types for which no
`to_json()` function was provided), a strong guarantee holds: if an exception is thrown, there are no changes to any
JSON value.
5. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
6. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
7. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
8. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
9. No-throw guarantee: this constructor never throws exceptions.
## Exceptions
1. (none)
2. The function does not throw exceptions.
3. (none)
4. (none)
5. The function can throw the following exceptions:
- Throws [`type_error.301`](../../home/exceptions.md#jsonexceptiontype_error301) if `type_deduction` is
`#!cpp false`, `manual_type` is `value_t::object`, but `init` contains an element which is not a pair whose first
element is a string. In this case, the constructor could not create an object. If `type_deduction` would have been
`#!cpp true`, an array would have been created. See `object(initializer_list_t)` for an example.
6. (none)
7. The function can throw the following exceptions:
- Throws [`invalid_iterator.201`](../../home/exceptions.md#jsonexceptioninvalid_iterator201) if iterators `first`
and `last` are not compatible (i.e., do not belong to the same JSON value). In this case, the range
`[first, last)` is undefined.
- Throws [`invalid_iterator.204`](../../home/exceptions.md#jsonexceptioninvalid_iterator204) if iterators `first`
and `last` belong to a primitive type (number, boolean, or string), but `first` does not point to the first
element anymore. In this case, the range `[first, last)` is undefined. See the example code below.
- Throws [`invalid_iterator.206`](../../home/exceptions.md#jsonexceptioninvalid_iterator206) if iterators `first`
and `last` belong to a `#!json null` value. In this case, the range `[first, last)` is undefined.
8. (none)
9. The function does not throw exceptions.
## Complexity
1. Constant.
2. Constant.
3. Usually linear in the size of the passed `val`, also depending on the implementation of the called `to_json()`
method.
4. Usually linear in the size of the passed `val`, also depending on the implementation of the called `to_json()`
method.
5. Linear in the size of the initializer list `init`.
6. Linear in `cnt`.
7. Linear in distance between `first` and `last`.
8. Linear in the size of `other`.
9. Constant.
## Notes
- Overload 5:
!!! note "Empty initializer list"
When used without parentheses around an empty initializer list, `basic_json()` is called instead of this
function, yielding the JSON `#!json null` value.
- Overload 7:
!!! info "Preconditions"
- Iterators `first` and `last` must be initialized. **This precondition is enforced with a
[runtime assertion](../../features/assertions.md).
- Range `[first, last)` is valid. Usually, this precondition cannot be checked efficiently. Only certain edge
cases are detected; see the description of the exceptions above. A violation of this precondition yields
undefined behavior.
!!! danger "Runtime assertion"
A precondition is enforced with a [runtime assertion](../../features/assertions.md).
- Overload 8:
!!! info "Postcondition"
`#!cpp *this == other`
- Overload 9:
!!! info "Postconditions"
- `#!cpp `*this` has the same value as `other` before the call.
- `other` is a JSON `#!json null` value
## Examples
??? example "Example: (1) create an empty value with a given type"
The following code shows the constructor for different `value_t` values.
```cpp
--8<-- "examples/basic_json__value_t.cpp"
```
Output:
```json
--8<-- "examples/basic_json__value_t.output"
```
??? example "Example: (2) create a `#!json null` object"
The following code shows the constructor with and without a null pointer parameter.
```cpp
--8<-- "examples/basic_json__nullptr_t.cpp"
```
Output:
```json
--8<-- "examples/basic_json__nullptr_t.output"
```
??? example "Example: (3) create a JSON value from compatible types"
The following code shows the constructor with several compatible types.
```cpp
--8<-- "examples/basic_json__CompatibleType.cpp"
```
Output:
```json
--8<-- "examples/basic_json__CompatibleType.output"
```
Note the output is platform-dependent.
??? example "Example: (5) create a container (array or object) from an initializer list"
The example below shows how JSON values are created from initializer lists.
```cpp
--8<-- "examples/basic_json__list_init_t.cpp"
```
Output:
```json
--8<-- "examples/basic_json__list_init_t.output"
```
??? example "Example: (6) construct an array with count copies of a given value"
The following code shows examples for creating arrays with several copies of a given value.
```cpp
--8<-- "examples/basic_json__size_type_basic_json.cpp"
```
Output:
```json
--8<-- "examples/basic_json__size_type_basic_json.output"
```
??? example "Example: (7) construct a JSON container given an iterator range"
The example below shows several ways to create JSON values by specifying a subrange with iterators.
```cpp
--8<-- "examples/basic_json__InputIt_InputIt.cpp"
```
Output:
```json
--8<-- "examples/basic_json__InputIt_InputIt.output"
```
??? example "Example: (8) copy constructor"
The following code shows an example for the copy constructor.
```cpp
--8<-- "examples/basic_json__basic_json.cpp"
```
Output:
```json
--8<-- "examples/basic_json__basic_json.output"
```
??? example "Example: (9) move constructor"
The code below shows the move constructor explicitly called via `std::move`.
```cpp
--8<-- "examples/basic_json__moveconstructor.cpp"
```
Output:
```json
--8<-- "examples/basic_json__moveconstructor.output"
```
## Version history
1. Since version 1.0.0.
2. Since version 1.0.0.
3. Since version 2.1.0.
4. Since version 3.2.0.
5. Since version 1.0.0.
6. Since version 1.0.0.
7. Since version 1.0.0.
8. Since version 1.0.0.
9. Since version 1.0.0.
File diff suppressed because one or more lines are too long
-768
View File
@@ -1,768 +0,0 @@
# nlohmann::basic_json::basic_json
```
// (1)
basic_json(const value_t v);
// (2)
basic_json(std::nullptr_t = nullptr) noexcept;
// (3)
template<typename CompatibleType>
basic_json(CompatibleType&& val) noexcept(noexcept(
JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
std::forward<CompatibleType>(val))));
// (4)
template<typename BasicJsonType>
basic_json(const BasicJsonType& val);
// (5)
basic_json(initializer_list_t init,
bool type_deduction = true,
value_t manual_type = value_t::array);
// (6)
basic_json(size_type cnt, const basic_json& val);
// (7)
basic_json(iterator first, iterator last);
basic_json(const_iterator first, const_iterator last);
// (8)
basic_json(const basic_json& other);
// (9)
basic_json(basic_json&& other) noexcept;
```
1. Create an empty JSON value with a given type. The value will be default initialized with an empty value which depends on the type:
| Value type | initial value |
| ---------- | ------------- |
| null | `null` |
| boolean | `false` |
| string | `""` |
| number | `0` |
| object | `{}` |
| array | `[]` |
| binary | empty array |
The postcondition of this constructor can be restored by calling [`clear()`](https://json.nlohmann.me/api/basic_json/clear/index.md).
1. Create a `null` JSON value. It either takes a null pointer as parameter (explicitly creating `null`) or no parameter (implicitly creating `null`). The passed null pointer itself is not read -- it is only used to choose the right constructor.
1. This is a "catch all" constructor for all compatible JSON types; that is, types for which a `to_json()` method exists. The constructor forwards the parameter `val` to that method (to `json_serializer<U>::to_json` method with `U = uncvref_t<CompatibleType>`, to be exact).
Template type `CompatibleType` includes, but is not limited to, the following types:
- **arrays**: [`array_t`](https://json.nlohmann.me/api/basic_json/array_t/index.md) and all kinds of compatible containers such as `std::vector`, `std::deque`, `std::list`, `std::forward_list`, `std::array`, `std::valarray`, `std::set`, `std::unordered_set`, `std::multiset`, and `std::unordered_multiset` with a `value_type` from which a `basic_json` value can be constructed.
- **objects**: [`object_t`](https://json.nlohmann.me/api/basic_json/object_t/index.md) and all kinds of compatible associative containers such as `std::map`, `std::unordered_map`, `std::multimap`, and `std::unordered_multimap` with a `key_type` compatible to `string_t` and a `value_type` from which a `basic_json` value can be constructed.
- **strings**: `string_t`, string literals, and all compatible string containers can be used.
- **numbers**: [`number_integer_t`](https://json.nlohmann.me/api/basic_json/number_integer_t/index.md), [`number_unsigned_t`](https://json.nlohmann.me/api/basic_json/number_unsigned_t/index.md), [`number_float_t`](https://json.nlohmann.me/api/basic_json/number_float_t/index.md), and all convertible number types such as `int`, `size_t`, `int64_t`, `float` or `double` can be used.
- **boolean**: `boolean_t` / `bool` can be used.
- **binary**: `binary_t` / `std::vector<uint8_t>` may be used; unfortunately because string literals cannot be distinguished from binary character arrays by the C++ type system, all types compatible with `const char*` will be directed to the string constructor instead. This is both for backwards compatibility and due to the fact that a binary type is not a standard JSON type.
See the examples below.
1. This is a constructor for existing `basic_json` types. It does not hijack copy/move constructors, since the parameter has different template arguments than the current ones.
The constructor tries to convert the internal `m_value` of the parameter. Each member value (object, array, string, etc.) is serialized via the corresponding `to_json()` overload. For objects and strings, the conversion requires that the *target* `basic_json` type's `object_t::key_type` (or `string_t`) be directly constructible from the *source* type's corresponding member type via `is_constructible`. If this requirement is not met, the conversion does not fail to compile; instead, it silently falls back to the array-conversion path, which represents objects as arrays of `[key, value]` pairs and strings as arrays of character codes. This is a known limitation tracked in [issue #3425](https://github.com/nlohmann/json/issues/3425).
1. Creates a JSON value of type array or object from the passed initializer list `init`. In case `type_deduction` is `true` (default), the type of the JSON value to be created is deducted from the initializer list `init` according to the following rules:
1. If the list is empty, an empty JSON object value `{}` is created.
1. If the list consists of pairs whose first element is a string, a JSON object value is created where the first elements of the pairs are treated as keys and the second elements are as values.
1. In all other cases, an array is created.
The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows:
1. The empty initializer list is written as `{}` which is exactly an empty JSON object.
1. C++ has no way of describing mapped types other than to list a list of pairs. As JSON requires that keys must be of type string, rule 2 is the weakest constraint one can pose on initializer lists to interpret them as an object.
1. In all other cases, the initializer list could not be interpreted as a JSON object type, so interpreting it as a JSON array type is safe.
With the rules described above, the following JSON values cannot be expressed by an initializer list:
- the empty array (`[]`): use `array(initializer_list_t)` with an empty initializer list in this case
- arrays whose elements satisfy rule 2: use `array(initializer_list_t)` with the same initializer list in this case
Function [`array()`](https://json.nlohmann.me/api/basic_json/array/index.md) and [`object()`](https://json.nlohmann.me/api/basic_json/object/index.md) force array and object creation from initializer lists, respectively.
Brace initialization yields arrays
Because this constructor takes an `initializer_list_t`, brace-initializing a `json`/`ordered_json` from another `json` value wraps it in a single-element array rather than copying it:
```
json j1 = "hello";
json j2{j1}; // [!] j2 is ["hello"], NOT a copy of j1
json j3(j1); // j3 is "hello" -- parentheses copy as expected
```
See the FAQ entry on [brace initialization](https://json.nlohmann.me/home/faq/#brace-initialization-yields-arrays) for the full explanation, an opt-in macro to change this behavior, and how to explicitly create a single-element array (`json::array({value})`) if that is what you want.
1. Constructs a JSON array value by creating `cnt` copies of a passed value. In case `cnt` is `0`, an empty array is created.
1. Constructs the JSON value with the contents of the range `[first, last)`. The semantics depend on the different types a JSON value can have:
- In case of a `null` type, [invalid_iterator.206](https://json.nlohmann.me/home/exceptions/#jsonexceptioninvalid_iterator206) is thrown.
- In case of other primitive types (number, boolean, or string), `first` must be `begin()` and `last` must be `end()`. In this case, the value is copied. Otherwise, [`invalid_iterator.204`](https://json.nlohmann.me/home/exceptions/#jsonexceptioninvalid_iterator204) is thrown.
- In case of structured types (array, object), the constructor behaves as similar versions for `std::vector` or `std::map`; that is, a JSON array or object is constructed from the values in the range.
1. Creates a copy of a given JSON value.
1. Move constructor. Constructs a JSON value with the contents of the given value `other` using move semantics. It "steals" the resources from `other` and leaves it as JSON `null` value.
## Template parameters
`CompatibleType` : a type such that:
```
- `CompatibleType` is not derived from `std::istream`,
- `CompatibleType` is not `basic_json` (to avoid hijacking copy/move constructors),
- `CompatibleType` is not a different `basic_json` type (i.e. with different template arguments)
- `CompatibleType` is not a `basic_json` nested type (e.g., `json_pointer`, `iterator`, etc.)
- `json_serializer<U>` (with `U = uncvref_t<CompatibleType>`) has a `to_json(basic_json_t&, CompatibleType&&)`
method
```
`BasicJsonType`: : a type such that:
```
- `BasicJsonType` is a `basic_json` type.
- `BasicJsonType` has different template arguments than `basic_json_t`.
**Note:** For cross-`basic_json` conversions to produce correct results, the target `basic_json`'s
`object_t::key_type` and `string_t` must be directly constructible from the source `basic_json`'s
corresponding types. See the description of overload (4) above for details on what happens when
this requirement is not met.
```
`U`: : `uncvref_t<CompatibleType>`
## Parameters
`v` (in) : the type of the value to create
`val` (in) : the value to be forwarded to the respective constructor
`init` (in) : initializer list with JSON values
`type_deduction` (in) : internal parameter; when set to `true`, the type of the JSON value is deducted from the initializer list `init`; when set to `false`, the type provided via `manual_type` is forced. This mode is used by the functions `array(initializer_list_t)` and `object(initializer_list_t)`.
`manual_type` (in) : internal parameter; when `type_deduction` is set to `false`, the created JSON value will use the provided type (only `value_t::array` and `value_t::object` are valid); when `type_deduction` is set to `true`, this parameter has no effect
`cnt` (in) : the number of JSON copies of `val` to create
`first` (in) : the beginning of the range to copy from (included)
`last` (in) : the end of the range to copy from (excluded)
`other` (in) : the JSON value to copy/move
## Exception safety
1. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
1. No-throw guarantee: this constructor never throws exceptions.
1. Depends on the called constructor. For types directly supported by the library (i.e., all types for which no `to_json()` function was provided), a strong guarantee holds: if an exception is thrown, there are no changes to any JSON value.
1. Depends on the called constructor. For types directly supported by the library (i.e., all types for which no `to_json()` function was provided), a strong guarantee holds: if an exception is thrown, there are no changes to any JSON value.
1. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
1. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
1. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
1. Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
1. No-throw guarantee: this constructor never throws exceptions.
## Exceptions
1. (none)
1. The function does not throw exceptions.
1. (none)
1. (none)
1. The function can throw the following exceptions:
- Throws [`type_error.301`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error301) if `type_deduction` is `false`, `manual_type` is `value_t::object`, but `init` contains an element which is not a pair whose first element is a string. In this case, the constructor could not create an object. If `type_deduction` would have been `true`, an array would have been created. See `object(initializer_list_t)` for an example.
1. (none)
1. The function can throw the following exceptions:
- Throws [`invalid_iterator.201`](https://json.nlohmann.me/home/exceptions/#jsonexceptioninvalid_iterator201) if iterators `first` and `last` are not compatible (i.e., do not belong to the same JSON value). In this case, the range `[first, last)` is undefined.
- Throws [`invalid_iterator.204`](https://json.nlohmann.me/home/exceptions/#jsonexceptioninvalid_iterator204) if iterators `first` and `last` belong to a primitive type (number, boolean, or string), but `first` does not point to the first element anymore. In this case, the range `[first, last)` is undefined. See the example code below.
- Throws [`invalid_iterator.206`](https://json.nlohmann.me/home/exceptions/#jsonexceptioninvalid_iterator206) if iterators `first` and `last` belong to a `null` value. In this case, the range `[first, last)` is undefined.
1. (none)
1. The function does not throw exceptions.
## Complexity
1. Constant.
1. Constant.
1. Usually linear in the size of the passed `val`, also depending on the implementation of the called `to_json()` method.
1. Usually linear in the size of the passed `val`, also depending on the implementation of the called `to_json()` method.
1. Linear in the size of the initializer list `init`.
1. Linear in `cnt`.
1. Linear in distance between `first` and `last`.
1. Linear in the size of `other`.
1. Constant.
## Notes
- Overload 5:
Empty initializer list
When used without parentheses around an empty initializer list, `basic_json()` is called instead of this function, yielding the JSON `null` value.
- Overload 7:
Preconditions
- Iterators `first` and `last` must be initialized. \*\*This precondition is enforced with a [runtime assertion](https://json.nlohmann.me/features/assertions/index.md).
- Range `[first, last)` is valid. Usually, this precondition cannot be checked efficiently. Only certain edge cases are detected; see the description of the exceptions above. A violation of this precondition yields undefined behavior.
Runtime assertion
A precondition is enforced with a [runtime assertion](https://json.nlohmann.me/features/assertions/index.md).
- Overload 8:
Postcondition
`*this == other`
- Overload 9:
Postconditions
- `` `*this `` has the same value as `other` before the call.
- `other` is a JSON `null` value
## Examples
Example: (1) create an empty value with a given type
The following code shows the constructor for different `value_t` values.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create the different JSON values with default values
json j_null(json::value_t::null);
json j_boolean(json::value_t::boolean);
json j_number_integer(json::value_t::number_integer);
json j_number_float(json::value_t::number_float);
json j_object(json::value_t::object);
json j_array(json::value_t::array);
json j_string(json::value_t::string);
// serialize the JSON values
std::cout << j_null << '\n';
std::cout << j_boolean << '\n';
std::cout << j_number_integer << '\n';
std::cout << j_number_float << '\n';
std::cout << j_object << '\n';
std::cout << j_array << '\n';
std::cout << j_string << '\n';
}
```
Output:
```
null
false
0
0.0
{}
[]
""
```
Example: (2) create a `null` object
The following code shows the constructor with and without a null pointer parameter.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// implicitly create a JSON null value
json j1;
// explicitly create a JSON null value
json j2(nullptr);
// serialize the JSON null value
std::cout << j1 << '\n' << j2 << '\n';
}
```
Output:
```
null
null
```
Example: (3) create a JSON value from compatible types
The following code shows the constructor with several compatible types.
```
#include <iostream>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// ============
// object types
// ============
// create an object from an object_t value
json::object_t object_value = { {"one", 1}, {"two", 2} };
json j_object_t(object_value);
// create an object from std::map
std::map<std::string, int> c_map
{
{"one", 1}, {"two", 2}, {"three", 3}
};
json j_map(c_map);
// create an object from std::unordered_map
std::unordered_map<const char*, double> c_umap
{
{"one", 1.2}, {"two", 2.3}, {"three", 3.4}
};
json j_umap(c_umap);
// create an object from std::multimap
std::multimap<std::string, bool> c_mmap
{
{"one", true}, {"two", true}, {"three", false}, {"three", true}
};
json j_mmap(c_mmap); // only one entry for key "three" is used
// create an object from std::unordered_multimap
std::unordered_multimap<std::string, bool> c_ummap
{
{"one", true}, {"two", true}, {"three", false}, {"three", true}
};
json j_ummap(c_ummap); // only one entry for key "three" is used
// serialize the JSON objects
std::cout << j_object_t << '\n';
std::cout << j_map << '\n';
std::cout << j_umap << '\n';
std::cout << j_mmap << '\n';
std::cout << j_ummap << "\n\n";
// ===========
// array types
// ===========
// create an array from an array_t value
json::array_t array_value = {"one", "two", 3, 4.5, false};
json j_array_t(array_value);
// create an array from std::vector
std::vector<int> c_vector {1, 2, 3, 4};
json j_vec(c_vector);
// create an array from std::valarray
std::valarray<short> c_valarray {10, 9, 8, 7};
json j_valarray(c_valarray);
// create an array from std::deque
std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6};
json j_deque(c_deque);
// create an array from std::list
std::list<bool> c_list {true, true, false, true};
json j_list(c_list);
// create an array from std::forward_list
std::forward_list<std::int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
json j_flist(c_flist);
// create an array from std::array
std::array<unsigned long, 4> c_array {{1, 2, 3, 4}};
json j_array(c_array);
// create an array from std::set
std::set<std::string> c_set {"one", "two", "three", "four", "one"};
json j_set(c_set); // only one entry for "one" is used
// create an array from std::unordered_set
std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"};
json j_uset(c_uset); // only one entry for "one" is used
// create an array from std::multiset
std::multiset<std::string> c_mset {"one", "two", "one", "four"};
json j_mset(c_mset); // both entries for "one" are used
// create an array from std::unordered_multiset
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
json j_umset(c_umset); // both entries for "one" are used
// serialize the JSON arrays
std::cout << j_array_t << '\n';
std::cout << j_vec << '\n';
std::cout << j_valarray << '\n';
std::cout << j_deque << '\n';
std::cout << j_list << '\n';
std::cout << j_flist << '\n';
std::cout << j_array << '\n';
std::cout << j_set << '\n';
std::cout << j_uset << '\n';
std::cout << j_mset << '\n';
std::cout << j_umset << "\n\n";
// ============
// string types
// ============
// create string from a string_t value
json::string_t string_value = "The quick brown fox jumps over the lazy dog.";
json j_string_t(string_value);
// create a JSON string directly from a string literal
json j_string_literal("The quick brown fox jumps over the lazy dog.");
// create string from std::string
std::string s_stdstring = "The quick brown fox jumps over the lazy dog.";
json j_stdstring(s_stdstring);
// serialize the JSON strings
std::cout << j_string_t << '\n';
std::cout << j_string_literal << '\n';
std::cout << j_stdstring << "\n\n";
// ============
// number types
// ============
// create a JSON number from number_integer_t
json::number_integer_t value_integer_t = -42;
json j_integer_t(value_integer_t);
// create a JSON number from number_unsigned_t
json::number_integer_t value_unsigned_t = 17;
json j_unsigned_t(value_unsigned_t);
// create a JSON number from an anonymous enum
enum { enum_value = 17 };
json j_enum(enum_value);
// create values of different integer types
short n_short = 42;
int n_int = -23;
long n_long = 1024;
int_least32_t n_int_least32_t = -17;
uint8_t n_uint8_t = 8;
// create (integer) JSON numbers
json j_short(n_short);
json j_int(n_int);
json j_long(n_long);
json j_int_least32_t(n_int_least32_t);
json j_uint8_t(n_uint8_t);
// create values of different floating-point types
json::number_float_t v_ok = 3.141592653589793;
json::number_float_t v_nan = NAN;
json::number_float_t v_infinity = INFINITY;
// create values of different floating-point types
float n_float = 42.23;
float n_float_nan = 1.0f / 0.0f;
double n_double = 23.42;
// create (floating point) JSON numbers
json j_ok(v_ok);
json j_nan(v_nan);
json j_infinity(v_infinity);
json j_float(n_float);
json j_float_nan(n_float_nan);
json j_double(n_double);
// serialize the JSON numbers
std::cout << j_integer_t << '\n';
std::cout << j_unsigned_t << '\n';
std::cout << j_enum << '\n';
std::cout << j_short << '\n';
std::cout << j_int << '\n';
std::cout << j_long << '\n';
std::cout << j_int_least32_t << '\n';
std::cout << j_uint8_t << '\n';
std::cout << j_ok << '\n';
std::cout << j_nan << '\n';
std::cout << j_infinity << '\n';
std::cout << j_float << '\n';
std::cout << j_float_nan << '\n';
std::cout << j_double << "\n\n";
// =============
// boolean types
// =============
// create boolean values
json j_truth = true;
json j_falsity = false;
// serialize the JSON booleans
std::cout << j_truth << '\n';
std::cout << j_falsity << '\n';
}
```
Output:
```
{"one":1,"two":2}
{"one":1,"three":3,"two":2}
{"one":1.2,"three":3.4,"two":2.3}
{"one":true,"three":false,"two":true}
{"one":true,"three":false,"two":true}
["one","two",3,4.5,false]
[1,2,3,4]
[10,9,8,7]
[1.2,2.3,3.4,5.6]
[true,true,false,true]
[12345678909876,23456789098765,34567890987654,45678909876543]
[1,2,3,4]
["four","one","three","two"]
["four","three","two","one"]
["four","one","one","two"]
["four","two","one","one"]
"The quick brown fox jumps over the lazy dog."
"The quick brown fox jumps over the lazy dog."
"The quick brown fox jumps over the lazy dog."
-42
17
17
42
-23
1024
-17
8
3.141592653589793
null
null
42.22999954223633
null
23.42
true
false
```
Note the output is platform-dependent.
Example: (5) create a container (array or object) from an initializer list
The example below shows how JSON values are created from initializer lists.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json j_empty_init_list = json({});
json j_object = { {"one", 1}, {"two", 2} };
json j_array = {1, 2, 3, 4};
json j_nested_object = { {"one", {1}}, {"two", {1, 2}} };
json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} };
// serialize the JSON value
std::cout << j_empty_init_list << '\n';
std::cout << j_object << '\n';
std::cout << j_array << '\n';
std::cout << j_nested_object << '\n';
std::cout << j_nested_array << '\n';
}
```
Output:
```
{}
{"one":1,"two":2}
[1,2,3,4]
{"one":[1],"two":[1,2]}
[[[1],"one"],[[1,2],"two"]]
```
Example: (6) construct an array with count copies of a given value
The following code shows examples for creating arrays with several copies of a given value.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create an array by creating copies of a JSON value
json value = "Hello";
json array_0 = json(0, value);
json array_1 = json(1, value);
json array_5 = json(5, value);
// serialize the JSON arrays
std::cout << array_0 << '\n';
std::cout << array_1 << '\n';
std::cout << array_5 << '\n';
}
```
Output:
```
[]
["Hello"]
["Hello","Hello","Hello","Hello","Hello"]
```
Example: (7) construct a JSON container given an iterator range
The example below shows several ways to create JSON values by specifying a subrange with iterators.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json j_array = {"alpha", "bravo", "charly", "delta", "easy"};
json j_number = 42;
json j_object = {{"one", "eins"}, {"two", "zwei"}};
// create copies using iterators
json j_array_range(j_array.begin() + 1, j_array.end() - 2);
json j_number_range(j_number.begin(), j_number.end());
json j_object_range(j_object.begin(), j_object.find("two"));
// serialize the values
std::cout << j_array_range << '\n';
std::cout << j_number_range << '\n';
std::cout << j_object_range << '\n';
// example for an exception
try
{
json j_invalid(j_number.begin() + 1, j_number.end());
}
catch (const json::invalid_iterator& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
["bravo","charly"]
42
{"one":"eins"}
[json.exception.invalid_iterator.204] iterators out of range
```
Example: (8) copy constructor
The following code shows an example for the copy constructor.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON array
json j1 = {"one", "two", 3, 4.5, false};
// create a copy
json j2(j1);
// serialize the JSON array
std::cout << j1 << " = " << j2 << '\n';
std::cout << std::boolalpha << (j1 == j2) << '\n';
}
```
Output:
```
["one","two",3,4.5,false] = ["one","two",3,4.5,false]
true
```
Example: (9) move constructor
The code below shows the move constructor explicitly called via `std::move`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON value
json a = 23;
// move contents of a to b
json b(std::move(a));
// serialize the JSON arrays
std::cout << a << '\n';
std::cout << b << '\n';
}
```
Output:
```
null
23
```
## Version history
1. Since version 1.0.0.
1. Since version 1.0.0.
1. Since version 2.1.0.
1. Since version 3.2.0.
1. Since version 1.0.0.
1. Since version 1.0.0.
1. Since version 1.0.0.
1. Since version 1.0.0.
1. Since version 1.0.0.
-42
View File
@@ -1,42 +0,0 @@
# <small>nlohmann::basic_json::</small>begin
```cpp
iterator begin() noexcept;
const_iterator begin() const noexcept;
```
Returns an iterator to the first element.
![Illustration from cppreference.com](../../images/range-begin-end.svg)
## Return value
iterator to the first element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
??? example
The following code shows an example for `begin()`.
```cpp
--8<-- "examples/begin.cpp"
```
Output:
```json
--8<-- "examples/begin.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-55
View File
@@ -1,55 +0,0 @@
# nlohmann::basic_json::begin
```
iterator begin() noexcept;
const_iterator begin() const noexcept;
```
Returns an iterator to the first element.
## Return value
iterator to the first element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
Example
The following code shows an example for `begin()`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create an array value
json array = {1, 2, 3, 4, 5};
// get an iterator to the first element
json::iterator it = array.begin();
// serialize the element that the iterator points to
std::cout << *it << '\n';
}
```
Output:
```
1
```
## Version history
- Added in version 1.0.0.
-66
View File
@@ -1,66 +0,0 @@
# <small>nlohmann::basic_json::</small>binary
```cpp
// (1)
static basic_json binary(const typename binary_t::container_type& init);
static basic_json binary(typename binary_t::container_type&& init);
// (2)
static basic_json binary(const typename binary_t::container_type& init,
std::uint8_t subtype);
static basic_json binary(typename binary_t::container_type&& init,
std::uint8_t subtype);
```
1. Creates a JSON binary array value from a given binary container.
2. Creates a JSON binary array value from a given binary container with subtype.
Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to
create a value for serialization to those formats.
## Parameters
`init` (in)
: container containing bytes to use as a binary type
`subtype` (in)
: subtype to use in CBOR, MessagePack, and BSON
## Return value
JSON binary array value
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Complexity
Linear in the size of `init`; constant for `typename binary_t::container_type&& init` versions.
## Notes
Note, this function exists because of the difficulty in correctly specifying the correct template overload in the
standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a `std::vector`. Because
JSON binary arrays are a non-standard extension, it was decided that it would be best to prevent automatic
initialization of a binary array type, for backwards compatibility and so it does not happen on accident.
## Examples
??? example
The following code shows how to create a binary value.
```cpp
--8<-- "examples/binary.cpp"
```
Output:
```json
--8<-- "examples/binary.output"
```
## Version history
- Added in version 3.8.0.
File diff suppressed because one or more lines are too long
-75
View File
@@ -1,75 +0,0 @@
# nlohmann::basic_json::binary
```
// (1)
static basic_json binary(const typename binary_t::container_type& init);
static basic_json binary(typename binary_t::container_type&& init);
// (2)
static basic_json binary(const typename binary_t::container_type& init,
std::uint8_t subtype);
static basic_json binary(typename binary_t::container_type&& init,
std::uint8_t subtype);
```
1. Creates a JSON binary array value from a given binary container.
1. Creates a JSON binary array value from a given binary container with subtype.
Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.
## Parameters
`init` (in) : container containing bytes to use as a binary type
`subtype` (in) : subtype to use in CBOR, MessagePack, and BSON
## Return value
JSON binary array value
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Complexity
Linear in the size of `init`; constant for `typename binary_t::container_type&& init` versions.
## Notes
Note, this function exists because of the difficulty in correctly specifying the correct template overload in the standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a `std::vector`. Because JSON binary arrays are a non-standard extension, it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.
## Examples
Example
The following code shows how to create a binary value.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create a binary vector
std::vector<std::uint8_t> vec = {0xCA, 0xFE, 0xBA, 0xBE};
// create a binary JSON value with subtype 42
json j = json::binary(vec, 42);
// output type and subtype
std::cout << "type: " << j.type_name() << ", subtype: " << j.get_binary().subtype() << std::endl;
}
```
Output:
```
type: binary, subtype: 42
```
## Version history
- Added in version 3.8.0.
-129
View File
@@ -1,129 +0,0 @@
# <small>nlohmann::basic_json::</small>binary_t
```cpp
using binary_t = byte_container_with_subtype<BinaryType>;
```
This type is a type designed to carry binary data that appears in various serialized formats, such as CBOR's Major Type
2, MessagePack's bin, and BSON's generic binary subtype. This type is NOT a part of standard JSON and exists solely for
compatibility with these binary types. As such, it is simply defined as an ordered sequence of zero or more byte values.
Additionally, as an implementation detail, the subtype of the binary data is carried around as a `std::uint64_t`, which
is compatible with both of the binary data formats that use binary subtyping, (though the specific numbering is
incompatible with each other, and it is up to the user to translate between them). The subtype is added to `BinaryType`
via the helper type [byte_container_with_subtype](../byte_container_with_subtype/index.md).
[CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type as:
> Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers
> (major type 0).
[MessagePack's documentation on the bin type
family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:
> Bin format family stores a byte array in 2, 3, or 5 bytes of extra bytes in addition to the size of the byte array.
[BSON's specifications](http://bsonspec.org/spec.html) describe several binary types; however, this type is intended to
represent the generic binary type which has the description:
> Generic binary subtype - This is the most commonly used binary subtype and should be the 'default' for drivers and
> tools.
None of these impose any limitations on the internal representation other than the basic unit of storage be some type of
array whose parts are decomposable into bytes.
The default representation of this binary format is a `#!cpp std::vector<std::uint8_t>`, which is a very common way to
represent a byte array in modern C++.
## Template parameters
`BinaryType`
: container type to store arrays
Although not formally expressed as a C++ concept, `BinaryType` must be default-constructible,
copy/move-constructible, and support `push_back()`, `.data()`, and `.size()`, because
[`byte_container_with_subtype`](../byte_container_with_subtype/index.md) derives directly from it. Its
`value_type` must additionally be exactly one byte wide (e.g., `std::uint8_t`/`char`/`std::byte`): the binary
serializers (CBOR, MessagePack, BSON, UBJSON) read and write the container's raw bytes via
`reinterpret_cast`, which is only correct for byte-sized elements -- a container like
`#!cpp std::vector<std::intptr_t>` will not work as `BinaryType`.
## Notes
#### Default type
The default values for `BinaryType` is `#!cpp std::vector<std::uint8_t>`.
#### Custom BinaryType behavior
When a custom `BinaryType` is configured (other than the default `#!cpp std::vector<std::uint8_t>`), you can assign
values of that type directly to a `basic_json` instance, and they will automatically be recognized as binary values
rather than arrays:
```cpp
using custom_json = nlohmann::basic_json<
nlohmann::ordered_map, // ObjectType
std::vector, // ArrayType
std::string, // StringType
bool, // BooleanType
std::int64_t, // NumberIntegerType
std::uint64_t, // NumberUnsignedType
double, // NumberFloatType
std::allocator, // AllocatorType
nlohmann::adl_serializer,
std::vector<std::byte> // Custom BinaryType
>;
std::vector<std::byte> data{std::byte{1}, std::byte{2}, std::byte{3}};
custom_json j = data; // Creates a binary value, not an array
assert(j.is_binary());
// Round-tripping works seamlessly
auto extracted = j.get<std::vector<std::byte>>();
assert(extracted == data);
```
This automatic type detection is a convenience feature that only applies to custom (non-default) `BinaryType` configurations.
The default `nlohmann::json` continues to treat `#!cpp std::vector<std::uint8_t>` as arrays for backward compatibility.
#### Storage
Binary Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of the
type `#!cpp binary_t*` must be dereferenced.
#### Notes on subtypes
- CBOR
- Binary values are represented as byte strings. Subtypes are written as tags.
- MessagePack
- If a subtype is given and the binary array contains exactly 1, 2, 4, 8, or 16 elements, the fixext family (fixext1,
fixext2, fixext4, fixext8) is used. For other sizes, the ext family (ext8, ext16, ext32) is used. The subtype is
then added as a signed 8-bit integer.
- If no subtype is given, the bin family (bin8, bin16, bin32) is used.
- BSON
- If a subtype is given, it is used and added as an unsigned 8-bit integer.
- If no subtype is given, the generic binary subtype 0x00 is used.
## Examples
??? example
The following code shows that `binary_t` is by default, a typedef to
`#!cpp nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>`.
```cpp
--8<-- "examples/binary_t.cpp"
```
Output:
```json
--8<-- "examples/binary_t.output"
```
## See also
- [byte_container_with_subtype](../byte_container_with_subtype/index.md)
## Version history
- Added in version 3.8.0. Changed the type of subtype to `std::uint64_t` in version 3.10.0.
File diff suppressed because one or more lines are too long
-127
View File
@@ -1,127 +0,0 @@
# nlohmann::basic_json::binary_t
```
using binary_t = byte_container_with_subtype<BinaryType>;
```
This type is a type designed to carry binary data that appears in various serialized formats, such as CBOR's Major Type 2, MessagePack's bin, and BSON's generic binary subtype. This type is NOT a part of standard JSON and exists solely for compatibility with these binary types. As such, it is simply defined as an ordered sequence of zero or more byte values.
Additionally, as an implementation detail, the subtype of the binary data is carried around as a `std::uint64_t`, which is compatible with both of the binary data formats that use binary subtyping, (though the specific numbering is incompatible with each other, and it is up to the user to translate between them). The subtype is added to `BinaryType` via the helper type [byte_container_with_subtype](https://json.nlohmann.me/api/byte_container_with_subtype/index.md).
[CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type as:
> Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers (major type 0).
[MessagePack's documentation on the bin type family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:
> Bin format family stores a byte array in 2, 3, or 5 bytes of extra bytes in addition to the size of the byte array.
[BSON's specifications](http://bsonspec.org/spec.html) describe several binary types; however, this type is intended to represent the generic binary type which has the description:
> Generic binary subtype - This is the most commonly used binary subtype and should be the 'default' for drivers and tools.
None of these impose any limitations on the internal representation other than the basic unit of storage be some type of array whose parts are decomposable into bytes.
The default representation of this binary format is a `std::vector<std::uint8_t>`, which is a very common way to represent a byte array in modern C++.
## Template parameters
`BinaryType` : container type to store arrays
```
Although not formally expressed as a C++ concept, `BinaryType` must be default-constructible,
copy/move-constructible, and support `push_back()`, `.data()`, and `.size()`, because
[`byte_container_with_subtype`](https://json.nlohmann.me/api/byte_container_with_subtype/index.md) derives directly from it. Its
`value_type` must additionally be exactly one byte wide (e.g., `std::uint8_t`/`char`/`std::byte`): the binary
serializers (CBOR, MessagePack, BSON, UBJSON) read and write the container's raw bytes via
`reinterpret_cast`, which is only correct for byte-sized elements -- a container like
`std::vector<std::intptr_t>` will not work as `BinaryType`.
```
## Notes
#### Default type
The default values for `BinaryType` is `std::vector<std::uint8_t>`.
#### Custom BinaryType behavior
When a custom `BinaryType` is configured (other than the default `std::vector<std::uint8_t>`), you can assign values of that type directly to a `basic_json` instance, and they will automatically be recognized as binary values rather than arrays:
```
using custom_json = nlohmann::basic_json<
nlohmann::ordered_map, // ObjectType
std::vector, // ArrayType
std::string, // StringType
bool, // BooleanType
std::int64_t, // NumberIntegerType
std::uint64_t, // NumberUnsignedType
double, // NumberFloatType
std::allocator, // AllocatorType
nlohmann::adl_serializer,
std::vector<std::byte> // Custom BinaryType
>;
std::vector<std::byte> data{std::byte{1}, std::byte{2}, std::byte{3}};
custom_json j = data; // Creates a binary value, not an array
assert(j.is_binary());
// Round-tripping works seamlessly
auto extracted = j.get<std::vector<std::byte>>();
assert(extracted == data);
```
This automatic type detection is a convenience feature that only applies to custom (non-default) `BinaryType` configurations. The default `nlohmann::json` continues to treat `std::vector<std::uint8_t>` as arrays for backward compatibility.
#### Storage
Binary Arrays are stored as pointers in a `basic_json` type. That is, for any access to array values, a pointer of the type `binary_t*` must be dereferenced.
#### Notes on subtypes
- CBOR
- Binary values are represented as byte strings. Subtypes are written as tags.
- MessagePack
- If a subtype is given and the binary array contains exactly 1, 2, 4, 8, or 16 elements, the fixext family (fixext1, fixext2, fixext4, fixext8) is used. For other sizes, the ext family (ext8, ext16, ext32) is used. The subtype is then added as a signed 8-bit integer.
- If no subtype is given, the bin family (bin8, bin16, bin32) is used.
- BSON
- If a subtype is given, it is used and added as an unsigned 8-bit integer.
- If no subtype is given, the generic binary subtype 0x00 is used.
## Examples
Example
The following code shows that `binary_t` is by default, a typedef to `nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>`.
```
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::cout << std::boolalpha << std::is_same<nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>, json::binary_t>::value << std::endl;
}
```
Output:
```
true
```
## See also
- [byte_container_with_subtype](https://json.nlohmann.me/api/byte_container_with_subtype/index.md)
## Version history
- Added in version 3.8.0. Changed the type of subtype to `std::uint64_t` in version 3.10.0.
-42
View File
@@ -1,42 +0,0 @@
# <small>nlohmann::basic_json::</small>boolean_t
```cpp
using boolean_t = BooleanType;
```
The type used to store JSON booleans.
[RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a type which differentiates the two
literals `#!json true` and `#!json false`.
To store boolean values in C++, a type is defined by the template parameter `BooleanType` which chooses the type to use.
## Notes
#### Default type
With the default values for `BooleanType` (`#!cpp bool`), the default value for `boolean_t` is `#!cpp bool`.
#### Storage
Boolean values are stored directly inside a `basic_json` type.
## Examples
??? example
The following code shows that `boolean_t` is by default, a typedef to `#!cpp bool`.
```cpp
--8<-- "examples/boolean_t.cpp"
```
Output:
```json
--8<-- "examples/boolean_t.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-50
View File
@@ -1,50 +0,0 @@
# nlohmann::basic_json::boolean_t
```
using boolean_t = BooleanType;
```
The type used to store JSON booleans.
[RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a type which differentiates the two literals `true` and `false`.
To store boolean values in C++, a type is defined by the template parameter `BooleanType` which chooses the type to use.
## Notes
#### Default type
With the default values for `BooleanType` (`bool`), the default value for `boolean_t` is `bool`.
#### Storage
Boolean values are stored directly inside a `basic_json` type.
## Examples
Example
The following code shows that `boolean_t` is by default, a typedef to `bool`.
```
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::cout << std::boolalpha << std::is_same<bool, json::boolean_t>::value << std::endl;
}
```
Output:
```
true
```
## Version history
- Added in version 1.0.0.
-41
View File
@@ -1,41 +0,0 @@
# <small>nlohmann::basic_json::</small>cbegin
```cpp
const_iterator cbegin() const noexcept;
```
Returns an iterator to the first element.
![Illustration from cppreference.com](../../images/range-begin-end.svg)
## Return value
iterator to the first element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
??? example
The following code shows an example for `cbegin()`.
```cpp
--8<-- "examples/cbegin.cpp"
```
Output:
```json
--8<-- "examples/cbegin.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-54
View File
@@ -1,54 +0,0 @@
# nlohmann::basic_json::cbegin
```
const_iterator cbegin() const noexcept;
```
Returns an iterator to the first element.
## Return value
iterator to the first element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
Example
The following code shows an example for `cbegin()`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create an array value
const json array = {1, 2, 3, 4, 5};
// get an iterator to the first element
json::const_iterator it = array.cbegin();
// serialize the element that the iterator points to
std::cout << *it << '\n';
}
```
Output:
```
1
```
## Version history
- Added in version 1.0.0.
-42
View File
@@ -1,42 +0,0 @@
# <small>nlohmann::basic_json::</small>cbor_tag_handler_t
```cpp
enum class cbor_tag_handler_t
{
error,
ignore,
store
};
```
This enumeration is used in the [`from_cbor`](from_cbor.md) function to choose how to treat tags:
error
: throw a `parse_error` exception in case of a tag
ignore
: ignore tags
store
: store tagged values as binary container with subtype (for bytes 0xd8..0xdb)
## Examples
??? example
The example below shows how the different values of the `cbor_tag_handler_t` influence the behavior of
[`from_cbor`](from_cbor.md) when reading a tagged byte string.
```cpp
--8<-- "examples/cbor_tag_handler_t.cpp"
```
Output:
```json
--8<-- "examples/cbor_tag_handler_t.output"
```
## Version history
- Added in version 3.9.0. Added value `store` in 3.10.0.
File diff suppressed because one or more lines are too long
@@ -1,67 +0,0 @@
# nlohmann::basic_json::cbor_tag_handler_t
```
enum class cbor_tag_handler_t
{
error,
ignore,
store
};
```
This enumeration is used in the [`from_cbor`](https://json.nlohmann.me/api/basic_json/from_cbor/index.md) function to choose how to treat tags:
error : throw a `parse_error` exception in case of a tag
ignore : ignore tags
store : store tagged values as binary container with subtype (for bytes 0xd8..0xdb)
## Examples
Example
The example below shows how the different values of the `cbor_tag_handler_t` influence the behavior of [`from_cbor`](https://json.nlohmann.me/api/basic_json/from_cbor/index.md) when reading a tagged byte string.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// tagged byte string
std::vector<std::uint8_t> vec = {{0xd8, 0x42, 0x44, 0xcA, 0xfe, 0xba, 0xbe}};
// cbor_tag_handler_t::error throws
try
{
auto b_throw_on_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::error);
}
catch (const json::parse_error& e)
{
std::cout << e.what() << std::endl;
}
// cbor_tag_handler_t::ignore ignores the tag
auto b_ignore_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::ignore);
std::cout << b_ignore_tag << std::endl;
// cbor_tag_handler_t::store stores the tag as binary subtype
auto b_store_tag = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::store);
std::cout << b_store_tag << std::endl;
}
```
Output:
```
[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0xD8
{"bytes":[202,254,186,190],"subtype":null}
{"bytes":[202,254,186,190],"subtype":66}
```
## Version history
- Added in version 3.9.0. Added value `store` in 3.10.0.
-41
View File
@@ -1,41 +0,0 @@
# <small>nlohmann::basic_json::</small>cend
```cpp
const_iterator cend() const noexcept;
```
Returns an iterator to one past the last element.
![Illustration from cppreference.com](../../images/range-begin-end.svg)
## Return value
iterator one past the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
??? example
The following code shows an example for `cend()`.
```cpp
--8<-- "examples/cend.cpp"
```
Output:
```json
--8<-- "examples/cend.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-57
View File
@@ -1,57 +0,0 @@
# nlohmann::basic_json::cend
```
const_iterator cend() const noexcept;
```
Returns an iterator to one past the last element.
## Return value
iterator one past the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
Example
The following code shows an example for `cend()`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create an array value
json array = {1, 2, 3, 4, 5};
// get an iterator to one past the last element
json::const_iterator it = array.cend();
// decrement the iterator to point to the last element
--it;
// serialize the element that the iterator points to
std::cout << *it << '\n';
}
```
Output:
```
5
```
## Version history
- Added in version 1.0.0.
-58
View File
@@ -1,58 +0,0 @@
# <small>nlohmann::basic_json::</small>clear
```cpp
void clear() noexcept;
```
Clears the content of a JSON value and resets it to the default value as if [`basic_json(value_t)`](basic_json.md) would
have been called with the current value type from [`type()`](type.md):
| Value type | initial value |
|------------|----------------------|
| null | `null` |
| boolean | `false` |
| string | `""` |
| number | `0` |
| binary | An empty byte vector |
| object | `{}` |
| array | `[]` |
Has the same effect as calling
```.cpp
*this = basic_json(type());
```
## Exception safety
No-throw guarantee: this function never throws exceptions.
## Complexity
Linear in the size of the JSON value.
## Notes
All iterators, pointers, and references related to this container are invalidated.
## Examples
??? example
The example below shows the effect of `clear()` to different
JSON types.
```cpp
--8<-- "examples/clear.cpp"
```
Output:
```json
--8<-- "examples/clear.output"
```
## Version history
- Added in version 1.0.0.
- Added support for binary types in version 3.8.0.
File diff suppressed because one or more lines are too long
-95
View File
@@ -1,95 +0,0 @@
# nlohmann::basic_json::clear
```
void clear() noexcept;
```
Clears the content of a JSON value and resets it to the default value as if [`basic_json(value_t)`](https://json.nlohmann.me/api/basic_json/basic_json/index.md) would have been called with the current value type from [`type()`](https://json.nlohmann.me/api/basic_json/type/index.md):
| Value type | initial value |
| ---------- | -------------------- |
| null | `null` |
| boolean | `false` |
| string | `""` |
| number | `0` |
| binary | An empty byte vector |
| object | `{}` |
| array | `[]` |
Has the same effect as calling
```
*this = basic_json(type());
```
## Exception safety
No-throw guarantee: this function never throws exceptions.
## Complexity
Linear in the size of the JSON value.
## Notes
All iterators, pointers, and references related to this container are invalidated.
## Examples
Example
The example below shows the effect of `clear()` to different JSON types.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hello, world";
// call clear()
j_null.clear();
j_boolean.clear();
j_number_integer.clear();
j_number_float.clear();
j_object.clear();
j_array.clear();
j_string.clear();
// serialize the cleared values()
std::cout << j_null << '\n';
std::cout << j_boolean << '\n';
std::cout << j_number_integer << '\n';
std::cout << j_number_float << '\n';
std::cout << j_object << '\n';
std::cout << j_array << '\n';
std::cout << j_string << '\n';
}
```
Output:
```
null
false
0
0.0
{}
[]
""
```
## Version history
- Added in version 1.0.0.
- Added support for binary types in version 3.8.0.
-119
View File
@@ -1,119 +0,0 @@
# <small>nlohmann::basic_json::</small>contains
```cpp
// (1)
bool contains(const typename object_t::key_type& key) const;
// (2)
template<typename KeyType>
bool contains(KeyType&& key) const;
// (3)
bool contains(const json_pointer& ptr) const;
```
1. Check whether an element exists in a JSON object with a key equivalent to `key`. If the element is not found or the
JSON value is not an object, `#!cpp false` is returned.
2. See 1. This overload is only available if `KeyType` is comparable with `#!cpp typename object_t::key_type` and
`#!cpp typename object_comparator_t::is_transparent` denotes a type.
3. Check whether the given JSON pointer `ptr` can be resolved in the current JSON value.
## Template parameters
`KeyType`
: A type for an object key other than [`json_pointer`](../json_pointer/index.md) that is comparable with
[`string_t`](string_t.md) using [`object_comparator_t`](object_comparator_t.md).
This can also be a string view (C++17).
## Parameters
`key` (in)
: key value to check its existence.
`ptr` (in)
: JSON pointer to check its existence.
## Return value
1. `#!cpp true` if an element with specified `key` exists. If no such element with such a key is found or the JSON value
is not an object, `#!cpp false` is returned.
2. See 1.
3. `#!cpp true` if the JSON pointer can be resolved to a stored value, `#!cpp false` otherwise.
## Exception safety
Strong exception safety: if an exception occurs, the original value stays intact.
## Exceptions
1. The function does not throw exceptions.
2. The function does not throw exceptions.
3. The function does not throw exceptions.
## Complexity
Logarithmic in the size of the JSON object.
## Notes
- This method always returns `#!cpp false` when executed on a JSON type that is not an object.
- This method can be executed on any JSON value type.
!!! info "Postconditions"
If `#!cpp j.contains(x)` returns `#!c true` for a key or JSON pointer `x`, then it is safe to call `j[x]`.
## Examples
??? example "Example: (1) check with key"
The example shows how `contains()` is used.
```cpp
--8<-- "examples/contains__object_t_key_type.cpp"
```
Output:
```json
--8<-- "examples/contains__object_t_key_type.output"
```
??? example "Example: (2) check with key using string_view"
The example shows how `contains()` is used.
```cpp
--8<-- "examples/contains__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/contains__keytype.c++17.output"
```
??? example "Example: (3) check with JSON pointer"
The example shows how `contains()` is used.
```cpp
--8<-- "examples/contains__json_pointer.cpp"
```
Output:
```json
--8<-- "examples/contains__json_pointer.output"
```
## See also
- [find](find.md) find a value in an object
- [count](count.md) returns the number of occurrences of a key
## Version history
1. Added in version 3.11.0.
2. Added in version 3.6.0. Extended template `KeyType` to support comparable types in version 3.11.0.
3. Added in version 3.7.0.
File diff suppressed because one or more lines are too long
-199
View File
@@ -1,199 +0,0 @@
# nlohmann::basic_json::contains
```
// (1)
bool contains(const typename object_t::key_type& key) const;
// (2)
template<typename KeyType>
bool contains(KeyType&& key) const;
// (3)
bool contains(const json_pointer& ptr) const;
```
1. Check whether an element exists in a JSON object with a key equivalent to `key`. If the element is not found or the JSON value is not an object, `false` is returned.
1. See 1. This overload is only available if `KeyType` is comparable with `typename object_t::key_type` and `typename object_comparator_t::is_transparent` denotes a type.
1. Check whether the given JSON pointer `ptr` can be resolved in the current JSON value.
## Template parameters
`KeyType` : A type for an object key other than [`json_pointer`](https://json.nlohmann.me/api/json_pointer/index.md) that is comparable with [`string_t`](https://json.nlohmann.me/api/basic_json/string_t/index.md) using [`object_comparator_t`](https://json.nlohmann.me/api/basic_json/object_comparator_t/index.md). This can also be a string view (C++17).
## Parameters
`key` (in) : key value to check its existence.
`ptr` (in) : JSON pointer to check its existence.
## Return value
1. `true` if an element with specified `key` exists. If no such element with such a key is found or the JSON value is not an object, `false` is returned.
1. See 1.
1. `true` if the JSON pointer can be resolved to a stored value, `false` otherwise.
## Exception safety
Strong exception safety: if an exception occurs, the original value stays intact.
## Exceptions
1. The function does not throw exceptions.
1. The function does not throw exceptions.
1. The function does not throw exceptions.
## Complexity
Logarithmic in the size of the JSON object.
## Notes
- This method always returns `false` when executed on a JSON type that is not an object.
- This method can be executed on any JSON value type.
Postconditions
If `j.contains(x)` returns `true` for a key or JSON pointer `x`, then it is safe to call `j[x]`.
## Examples
Example: (1) check with key
The example shows how `contains()` is used.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace nlohmann::literals;
int main()
{
// create some JSON values
json j_object = R"( {"key": "value"} )"_json;
json j_array = R"( [1, 2, 3] )"_json;
// call contains
std::cout << std::boolalpha <<
"j_object contains 'key': " << j_object.contains("key") << '\n' <<
"j_object contains 'another': " << j_object.contains("another") << '\n' <<
"j_array contains 'key': " << j_array.contains("key") << std::endl;
}
```
Output:
```
j_object contains 'key': true
j_object contains 'another': false
j_array contains 'key': false
```
Example: (2) check with key using string_view
The example shows how `contains()` is used.
```
#include <iostream>
#include <string_view>
#include <nlohmann/json.hpp>
using namespace std::string_view_literals;
using json = nlohmann::json;
using namespace nlohmann::literals;
int main()
{
// create some JSON values
json j_object = R"( {"key": "value"} )"_json;
json j_array = R"( [1, 2, 3] )"_json;
// call contains
std::cout << std::boolalpha <<
"j_object contains 'key': " << j_object.contains("key"sv) << '\n' <<
"j_object contains 'another': " << j_object.contains("another"sv) << '\n' <<
"j_array contains 'key': " << j_array.contains("key"sv) << std::endl;
}
```
Output:
```
j_object contains 'key': true
j_object contains 'another': false
j_array contains 'key': false
```
Example: (3) check with JSON pointer
The example shows how `contains()` is used.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace nlohmann::literals;
int main()
{
// create a JSON value
json j =
{
{"number", 1}, {"string", "foo"}, {"array", {1, 2}}
};
std::cout << std::boolalpha
<< j.contains("/number"_json_pointer) << '\n'
<< j.contains("/string"_json_pointer) << '\n'
<< j.contains("/array"_json_pointer) << '\n'
<< j.contains("/array/1"_json_pointer) << '\n'
<< j.contains("/array/-"_json_pointer) << '\n'
<< j.contains("/array/4"_json_pointer) << '\n'
<< j.contains("/baz"_json_pointer) << std::endl;
try
{
// try to use an array index with leading '0'
j.contains("/array/01"_json_pointer);
}
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
try
{
// try to use an array index that is not a number
j.contains("/array/one"_json_pointer);
}
catch (const json::parse_error& e)
{
std::cout << e.what() << '\n';
}
}
```
Output:
```
true
true
true
true
false
false
false
```
## See also
- [find](https://json.nlohmann.me/api/basic_json/find/index.md) find a value in an object
- [count](https://json.nlohmann.me/api/basic_json/count/index.md) returns the number of occurrences of a key
## Version history
1. Added in version 3.11.0.
1. Added in version 3.6.0. Extended template `KeyType` to support comparable types in version 3.11.0.
1. Added in version 3.7.0.
-83
View File
@@ -1,83 +0,0 @@
# <small>nlohmann::basic_json::</small>count
```cpp
// (1)
size_type count(const typename object_t::key_type& key) const;
// (2)
template<typename KeyType>
size_type count(KeyType&& key) const;
```
1. Returns the number of elements with key `key`. If `ObjectType` is the default `std::map` type, the return value will
always be `0` (`key` was not found) or `1` (`key` was found).
2. See 1. This overload is only available if `KeyType` is comparable with `#!cpp typename object_t::key_type` and
`#!cpp typename object_comparator_t::is_transparent` denotes a type.
## Template parameters
`KeyType`
: A type for an object key other than [`json_pointer`](../json_pointer/index.md) that is comparable with
[`string_t`](string_t.md) using [`object_comparator_t`](object_comparator_t.md).
This can also be a string view (C++17).
## Parameters
`key` (in)
: key value of the element to count.
## Return value
Number of elements with key `key`. If the JSON value is not an object, the return value will be `0`.
## Exception safety
Strong exception safety: if an exception occurs, the original value stays intact.
## Complexity
Logarithmic in the size of the JSON object.
## Notes
This method always returns `0` when executed on a JSON type that is not an object.
## Examples
??? example "Example: (1) count number of elements"
The example shows how `count()` is used.
```cpp
--8<-- "examples/count__object_t_key_type.cpp"
```
Output:
```json
--8<-- "examples/count__object_t_key_type.output"
```
??? example "Example: (2) count number of elements using string_view"
The example shows how `count()` is used.
```cpp
--8<-- "examples/count__keytype.c++17.cpp"
```
Output:
```json
--8<-- "examples/count__keytype.c++17.output"
```
## See also
- [find](find.md) find a value in an object
- [contains](contains.md) checks whether a key exists
## Version history
1. Added in version 3.11.0.
2. Added in version 1.0.0. Changed parameter `key` type to `KeyType&&` in version 3.11.0.
File diff suppressed because one or more lines are too long
-115
View File
@@ -1,115 +0,0 @@
# nlohmann::basic_json::count
```
// (1)
size_type count(const typename object_t::key_type& key) const;
// (2)
template<typename KeyType>
size_type count(KeyType&& key) const;
```
1. Returns the number of elements with key `key`. If `ObjectType` is the default `std::map` type, the return value will always be `0` (`key` was not found) or `1` (`key` was found).
1. See 1. This overload is only available if `KeyType` is comparable with `typename object_t::key_type` and `typename object_comparator_t::is_transparent` denotes a type.
## Template parameters
`KeyType` : A type for an object key other than [`json_pointer`](https://json.nlohmann.me/api/json_pointer/index.md) that is comparable with [`string_t`](https://json.nlohmann.me/api/basic_json/string_t/index.md) using [`object_comparator_t`](https://json.nlohmann.me/api/basic_json/object_comparator_t/index.md). This can also be a string view (C++17).
## Parameters
`key` (in) : key value of the element to count.
## Return value
Number of elements with key `key`. If the JSON value is not an object, the return value will be `0`.
## Exception safety
Strong exception safety: if an exception occurs, the original value stays intact.
## Complexity
Logarithmic in the size of the JSON object.
## Notes
This method always returns `0` when executed on a JSON type that is not an object.
## Examples
Example: (1) count number of elements
The example shows how `count()` is used.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON object
json j_object = {{"one", 1}, {"two", 2}};
// call count()
auto count_two = j_object.count("two");
auto count_three = j_object.count("three");
// print values
std::cout << "number of elements with key \"two\": " << count_two << '\n';
std::cout << "number of elements with key \"three\": " << count_three << '\n';
}
```
Output:
```
number of elements with key "two": 1
number of elements with key "three": 0
```
Example: (2) count number of elements using string_view
The example shows how `count()` is used.
```
#include <iostream>
#include <string_view>
#include <nlohmann/json.hpp>
using namespace std::string_view_literals;
using json = nlohmann::json;
int main()
{
// create a JSON object
json j_object = {{"one", 1}, {"two", 2}};
// call count()
auto count_two = j_object.count("two"sv);
auto count_three = j_object.count("three"sv);
// print values
std::cout << "number of elements with key \"two\": " << count_two << '\n';
std::cout << "number of elements with key \"three\": " << count_three << '\n';
}
```
Output:
```
number of elements with key "two": 1
number of elements with key "three": 0
```
## See also
- [find](https://json.nlohmann.me/api/basic_json/find/index.md) find a value in an object
- [contains](https://json.nlohmann.me/api/basic_json/contains/index.md) checks whether a key exists
## Version history
1. Added in version 3.11.0.
1. Added in version 1.0.0. Changed parameter `key` type to `KeyType&&` in version 3.11.0.
-41
View File
@@ -1,41 +0,0 @@
# <small>nlohmann::basic_json::</small>crbegin
```cpp
const_reverse_iterator crbegin() const noexcept;
```
Returns an iterator to the reverse-beginning; that is, the last element.
![Illustration from cppreference.com](../../images/range-rbegin-rend.svg)
## Return value
reverse iterator to the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
??? example
The following code shows an example for `crbegin()`.
```cpp
--8<-- "examples/crbegin.cpp"
```
Output:
```json
--8<-- "examples/crbegin.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-54
View File
@@ -1,54 +0,0 @@
# nlohmann::basic_json::crbegin
```
const_reverse_iterator crbegin() const noexcept;
```
Returns an iterator to the reverse-beginning; that is, the last element.
## Return value
reverse iterator to the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
Example
The following code shows an example for `crbegin()`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create an array value
json array = {1, 2, 3, 4, 5};
// get an iterator to the reverse-beginning
json::const_reverse_iterator it = array.crbegin();
// serialize the element that the iterator points to
std::cout << *it << '\n';
}
```
Output:
```
5
```
## Version history
- Added in version 1.0.0.
-42
View File
@@ -1,42 +0,0 @@
# <small>nlohmann::basic_json::</small>crend
```cpp
const_reverse_iterator crend() const noexcept;
```
Returns an iterator to the reverse-end; that is, one before the first element. This element acts as a placeholder,
attempting to access it results in undefined behavior.
![Illustration from cppreference.com](../../images/range-rbegin-rend.svg)
## Return value
reverse iterator to the element following the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
??? example
The following code shows an example for `crend()`.
```cpp
--8<-- "examples/crend.cpp"
```
Output:
```json
--8<-- "examples/crend.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-57
View File
@@ -1,57 +0,0 @@
# nlohmann::basic_json::crend
```
const_reverse_iterator crend() const noexcept;
```
Returns an iterator to the reverse-end; that is, one before the first element. This element acts as a placeholder, attempting to access it results in undefined behavior.
## Return value
reverse iterator to the element following the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
Example
The following code shows an example for `crend()`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create an array value
json array = {1, 2, 3, 4, 5};
// get an iterator to the reverse-end
json::const_reverse_iterator it = array.crend();
// increment the iterator to point to the first element
--it;
// serialize the element that the iterator points to
std::cout << *it << '\n';
}
```
Output:
```
1
```
## Version history
- Added in version 1.0.0.
@@ -1,35 +0,0 @@
# <small>nlohmann::basic_json::</small>default_object_comparator_t
```cpp
using default_object_comparator_t = std::less<StringType>; // until C++14
using default_object_comparator_t = std::less<>; // since C++14
```
The default comparator used by [`object_t`](object_t.md).
Since C++14 a transparent comparator is used which prevents unnecessary string construction
when looking up a key in an object.
The actual comparator used depends on [`object_t`](object_t.md) and can be obtained via
[`object_comparator_t`](object_comparator_t.md).
## Examples
??? example
The example below demonstrates the default comparator.
```cpp
--8<-- "examples/default_object_comparator_t.cpp"
```
Output:
```json
--8<-- "examples/default_object_comparator_t.output"
```
## Version history
- Added in version 3.11.0.
File diff suppressed because one or more lines are too long
@@ -1,44 +0,0 @@
# nlohmann::basic_json::default_object_comparator_t
```
using default_object_comparator_t = std::less<StringType>; // until C++14
using default_object_comparator_t = std::less<>; // since C++14
```
The default comparator used by [`object_t`](https://json.nlohmann.me/api/basic_json/object_t/index.md).
Since C++14 a transparent comparator is used which prevents unnecessary string construction when looking up a key in an object.
The actual comparator used depends on [`object_t`](https://json.nlohmann.me/api/basic_json/object_t/index.md) and can be obtained via [`object_comparator_t`](https://json.nlohmann.me/api/basic_json/object_comparator_t/index.md).
## Examples
Example
The example below demonstrates the default comparator.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::cout << std::boolalpha
<< "one < two : " << json::default_object_comparator_t{}("one", "two") << "\n"
<< "three < four : " << json::default_object_comparator_t{}("three", "four") << std::endl;
}
```
Output:
```
one < two : true
three < four : false
```
## Version history
- Added in version 3.11.0.
-65
View File
@@ -1,65 +0,0 @@
# <small>nlohmann::basic_json::</small>diff
```cpp
static basic_json diff(const basic_json& source,
const basic_json& target);
```
Creates a [JSON Patch](http://jsonpatch.com) so that value `source` can be changed into the value `target` by calling
[`patch`](patch.md) function.
For two JSON values `source` and `target`, the following code yields always `#!cpp true`:
```cpp
source.patch(diff(source, target)) == target;
```
## Parameters
`source` (in)
: JSON value to compare from
`target` (in)
: JSON value to compare against
## Return value
a JSON patch to convert the `source` to `target`
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Complexity
Linear in the lengths of `source` and `target`.
## Notes
Currently, only `remove`, `add`, and `replace` operations are generated.
## Examples
??? example
The following code shows how a JSON patch is created as a diff for two JSON values.
```cpp
--8<-- "examples/diff.cpp"
```
Output:
```json
--8<-- "examples/diff.output"
```
## See also
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
- [patch](patch.md) applies a JSON Patch
- [patch_inplace](patch_inplace.md) applies a JSON Patch in place
- [merge_patch](merge_patch.md) applies a JSON Merge Patch
## Version history
- Added in version 2.0.0.
File diff suppressed because one or more lines are too long
-123
View File
@@ -1,123 +0,0 @@
# nlohmann::basic_json::diff
```
static basic_json diff(const basic_json& source,
const basic_json& target);
```
Creates a [JSON Patch](http://jsonpatch.com) so that value `source` can be changed into the value `target` by calling [`patch`](https://json.nlohmann.me/api/basic_json/patch/index.md) function.
For two JSON values `source` and `target`, the following code yields always `true`:
```
source.patch(diff(source, target)) == target;
```
## Parameters
`source` (in) : JSON value to compare from
`target` (in) : JSON value to compare against
## Return value
a JSON patch to convert the `source` to `target`
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
## Complexity
Linear in the lengths of `source` and `target`.
## Notes
Currently, only `remove`, `add`, and `replace` operations are generated.
## Examples
Example
The following code shows how a JSON patch is created as a diff for two JSON values.
```
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace nlohmann::literals;
int main()
{
// the source document
json source = R"(
{
"baz": "qux",
"foo": "bar"
}
)"_json;
// the target document
json target = R"(
{
"baz": "boo",
"hello": [
"world"
]
}
)"_json;
// create the patch
json patch = json::diff(source, target);
// roundtrip
json patched_source = source.patch(patch);
// output patch and roundtrip result
std::cout << std::setw(4) << patch << "\n\n"
<< std::setw(4) << patched_source << std::endl;
}
```
Output:
```
[
{
"op": "replace",
"path": "/baz",
"value": "boo"
},
{
"op": "remove",
"path": "/foo"
},
{
"op": "add",
"path": "/hello",
"value": [
"world"
]
}
]
{
"baz": "boo",
"hello": [
"world"
]
}
```
## See also
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
- [patch](https://json.nlohmann.me/api/basic_json/patch/index.md) applies a JSON Patch
- [patch_inplace](https://json.nlohmann.me/api/basic_json/patch_inplace/index.md) applies a JSON Patch in place
- [merge_patch](https://json.nlohmann.me/api/basic_json/merge_patch/index.md) applies a JSON Merge Patch
## Version history
- Added in version 2.0.0.
-85
View File
@@ -1,85 +0,0 @@
# <small>nlohmann::basic_json::</small>dump
```cpp
string_t dump(const int indent = -1,
const char indent_char = ' ',
const bool ensure_ascii = false,
const error_handler_t error_handler = error_handler_t::strict) const;
```
Serialization function for JSON values. The function tries to mimic Python's
[`json.dumps()` function](https://docs.python.org/2/library/json.html#json.dump), and currently supports its `indent`
and `ensure_ascii` parameters.
## Parameters
`indent` (in)
: If `indent` is nonnegative, then array elements and object members will be pretty-printed with that indent level. An
indent level of `0` will only insert newlines. `-1` (the default) selects the most compact representation.
`indent_char` (in)
: The character to use for indentation if `indent` is greater than `0`. The default is ` ` (space).
`ensure_ascii` (in)
: If `ensure_ascii` is true, all non-ASCII characters in the output are escaped with `\uXXXX` sequences, and the
result consists of ASCII characters only.
`error_handler` (in)
: how to react on decoding errors; there are three possible values (see [`error_handler_t`](error_handler_t.md):
`strict` (throws an exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences
with U+FFFD), and `ignore` (ignore invalid UTF-8 sequences during serialization; all valid bytes are copied to the
output unchanged, and invalid bytes are dropped)).
## Return value
string containing the serialization of the JSON value
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
## Exceptions
Throws [`type_error.316`](../../home/exceptions.md#jsonexceptiontype_error316) if a string stored inside the JSON value
is not UTF-8 encoded and `error_handler` is set to `strict`
## Complexity
Linear.
## Notes
Binary values are serialized as an object containing two keys:
- "bytes": an array of bytes as integers
- "subtype": the subtype as integer or `#!json null` if the binary has no subtype
## Examples
??? example
The following example shows the effect of different `indent`, `indent_char`, and `ensure_ascii` parameters to the
result of the serialization.
```cpp
--8<-- "examples/dump.cpp"
```
Output:
```json
--8<-- "examples/dump.output"
```
## See also
- [to_string](to_string.md) returns a string representation of a JSON value
- [operator<<](../operator_ltlt.md) serialize to stream
- [Serialization](../../features/serialization.md) - the serialization article
## Version history
- Added in version 1.0.0.
- Indentation character `indent_char`, option `ensure_ascii` and exceptions added in version 3.0.0.
- Error handlers added in version 3.4.0.
- Serialization of binary values added in version 3.8.0.
File diff suppressed because one or more lines are too long
-173
View File
@@ -1,173 +0,0 @@
# nlohmann::basic_json::dump
```
string_t dump(const int indent = -1,
const char indent_char = ' ',
const bool ensure_ascii = false,
const error_handler_t error_handler = error_handler_t::strict) const;
```
Serialization function for JSON values. The function tries to mimic Python's [`json.dumps()` function](https://docs.python.org/2/library/json.html#json.dump), and currently supports its `indent` and `ensure_ascii` parameters.
## Parameters
`indent` (in) : If `indent` is nonnegative, then array elements and object members will be pretty-printed with that indent level. An indent level of `0` will only insert newlines. `-1` (the default) selects the most compact representation.
`indent_char` (in) : The character to use for indentation if `indent` is greater than `0`. The default is (space).
`ensure_ascii` (in) : If `ensure_ascii` is true, all non-ASCII characters in the output are escaped with `\uXXXX` sequences, and the result consists of ASCII characters only.
`error_handler` (in) : how to react on decoding errors; there are three possible values (see [`error_handler_t`](https://json.nlohmann.me/api/basic_json/error_handler_t/index.md): `strict` (throws an exception in case a decoding error occurs; default), `replace` (replace invalid UTF-8 sequences with U+FFFD), and `ignore` (ignore invalid UTF-8 sequences during serialization; all valid bytes are copied to the output unchanged, and invalid bytes are dropped)).
## Return value
string containing the serialization of the JSON value
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
## Exceptions
Throws [`type_error.316`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error316) if a string stored inside the JSON value is not UTF-8 encoded and `error_handler` is set to `strict`
## Complexity
Linear.
## Notes
Binary values are serialized as an object containing two keys:
- "bytes": an array of bytes as integers
- "subtype": the subtype as integer or `null` if the binary has no subtype
## Examples
Example
The following example shows the effect of different `indent`, `indent_char`, and `ensure_ascii` parameters to the result of the serialization.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hellö 😀!";
// call dump()
std::cout << "objects:" << '\n'
<< j_object.dump() << "\n\n"
<< j_object.dump(-1) << "\n\n"
<< j_object.dump(0) << "\n\n"
<< j_object.dump(4) << "\n\n"
<< j_object.dump(1, '\t') << "\n\n";
std::cout << "arrays:" << '\n'
<< j_array.dump() << "\n\n"
<< j_array.dump(-1) << "\n\n"
<< j_array.dump(0) << "\n\n"
<< j_array.dump(4) << "\n\n"
<< j_array.dump(1, '\t') << "\n\n";
std::cout << "strings:" << '\n'
<< j_string.dump() << '\n'
<< j_string.dump(-1, ' ', true) << '\n';
// create JSON value with invalid UTF-8 byte sequence
json j_invalid = "ä\xA9ü";
try
{
std::cout << j_invalid.dump() << std::endl;
}
catch (const json::type_error& e)
{
std::cout << e.what() << std::endl;
}
std::cout << "string with replaced invalid characters: "
<< j_invalid.dump(-1, ' ', false, json::error_handler_t::replace)
<< "\nstring with ignored invalid characters: "
<< j_invalid.dump(-1, ' ', false, json::error_handler_t::ignore)
<< '\n';
}
```
Output:
```
objects:
{"one":1,"two":2}
{"one":1,"two":2}
{
"one": 1,
"two": 2
}
{
"one": 1,
"two": 2
}
{
"one": 1,
"two": 2
}
arrays:
[1,2,4,8,16]
[1,2,4,8,16]
[
1,
2,
4,
8,
16
]
[
1,
2,
4,
8,
16
]
[
1,
2,
4,
8,
16
]
strings:
"Hellö 😀!"
"Hell\u00f6 \ud83d\ude00!"
[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9
string with replaced invalid characters: "äü"
string with ignored invalid characters: "äü"
```
## See also
- [to_string](https://json.nlohmann.me/api/basic_json/to_string/index.md) returns a string representation of a JSON value
- [operator\<<](https://json.nlohmann.me/api/operator_ltlt/index.md) serialize to stream
- [Serialization](https://json.nlohmann.me/features/serialization/index.md) - the serialization article
## Version history
- Added in version 1.0.0.
- Indentation character `indent_char`, option `ensure_ascii` and exceptions added in version 3.0.0.
- Error handlers added in version 3.4.0.
- Serialization of binary values added in version 3.8.0.
-71
View File
@@ -1,71 +0,0 @@
# <small>nlohmann::basic_json::</small>emplace
```cpp
template<class... Args>
std::pair<iterator, bool> emplace(Args&& ... args);
```
Inserts a new element into a JSON object constructed in-place with the given `args` if there is no element with the key
in the container. If the function is called on a JSON null value, an empty object is created before appending the value
created from `args`.
## Template parameters
`Args`
: compatible types to create a `basic_json` object
## Iterator invalidation
For [`ordered_json`](../ordered_json.md), adding a value to an object can yield a reallocation, in which case all
iterators (including the `end()` iterator) and all references to the elements are invalidated.
## Parameters
`args` (in)
: arguments to forward to a constructor of `basic_json`
## Return value
a pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happened, and
a `#!cpp bool` denoting whether the insertion took place.
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
## Exceptions
Throws [`type_error.311`](../../home/exceptions.md#jsonexceptiontype_error311) when called on a type other than JSON
object or `#!json null`; example: `"cannot use emplace() with number"`
## Complexity
Logarithmic in the size of the container, O(log(`size()`)).
## Examples
??? example
The example shows how `emplace()` can be used to add elements to a JSON object. Note how the `#!json null` value was
silently converted to a JSON object. Further note how no value is added if there was already one value stored with
the same key.
```cpp
--8<-- "examples/emplace.cpp"
```
Output:
```json
--8<-- "examples/emplace.output"
```
## See also
- [emplace_back](emplace_back.md) add a value to an array
- [insert](insert.md) add values to an array/object
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history
- Since version 2.0.8.
File diff suppressed because one or more lines are too long
-97
View File
@@ -1,97 +0,0 @@
# nlohmann::basic_json::emplace
```
template<class... Args>
std::pair<iterator, bool> emplace(Args&& ... args);
```
Inserts a new element into a JSON object constructed in-place with the given `args` if there is no element with the key in the container. If the function is called on a JSON null value, an empty object is created before appending the value created from `args`.
## Template parameters
`Args` : compatible types to create a `basic_json` object
## Iterator invalidation
For [`ordered_json`](https://json.nlohmann.me/api/ordered_json/index.md), adding a value to an object can yield a reallocation, in which case all iterators (including the `end()` iterator) and all references to the elements are invalidated.
## Parameters
`args` (in) : arguments to forward to a constructor of `basic_json`
## Return value
a pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happened, and a `bool` denoting whether the insertion took place.
## Exception safety
Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
## Exceptions
Throws [`type_error.311`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error311) when called on a type other than JSON object or `null`; example: `"cannot use emplace() with number"`
## Complexity
Logarithmic in the size of the container, O(log(`size()`)).
## Examples
Example
The example shows how `emplace()` can be used to add elements to a JSON object. Note how the `null` value was silently converted to a JSON object. Further note how no value is added if there was already one value stored with the same key.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json object = {{"one", 1}, {"two", 2}};
json null;
// print values
std::cout << object << '\n';
std::cout << null << '\n';
// add values
auto res1 = object.emplace("three", 3);
null.emplace("A", "a");
null.emplace("B", "b");
// the following call will not add an object, because there is already
// a value stored at key "B"
auto res2 = null.emplace("B", "c");
// print values
std::cout << object << '\n';
std::cout << *res1.first << " " << std::boolalpha << res1.second << '\n';
std::cout << null << '\n';
std::cout << *res2.first << " " << std::boolalpha << res2.second << '\n';
}
```
Output:
```
{"one":1,"two":2}
null
{"one":1,"three":3,"two":2}
3 true
{"A":"a","B":"b"}
"b" false
```
## See also
- [emplace_back](https://json.nlohmann.me/api/basic_json/emplace_back/index.md) add a value to an array
- [insert](https://json.nlohmann.me/api/basic_json/insert/index.md) add values to an array/object
- [Modifying values](https://json.nlohmann.me/features/modifying_values/index.md) - the article on modifying values
## Version history
- Since version 2.0.8.
-66
View File
@@ -1,66 +0,0 @@
# <small>nlohmann::basic_json::</small>emplace_back
```cpp
template<class... Args>
reference emplace_back(Args&& ... args);
```
Creates a JSON value from the passed parameters `args` to the end of the JSON value. If the function is called on a JSON
`#!json null` value, an empty array is created before appending the value created from `args`.
## Template parameters
`Args`
: compatible types to create a `basic_json` object
## Iterator invalidation
By adding an element to the end of the array, a reallocation can happen, in which case all iterators (including the
[`end()`](end.md) iterator) and all references to the elements are invalidated. Otherwise, only the [`end()`](end.md)
iterator is invalidated.
## Parameters
`args` (in)
: arguments to forward to a constructor of `basic_json`
## Return value
reference to the inserted element
## Exceptions
Throws [`type_error.311`](../../home/exceptions.md#jsonexceptiontype_error311) when called on a type other than JSON
array or `#!json null`; example: `"cannot use emplace_back() with number"`
## Complexity
Amortized constant.
## Examples
??? example
The example shows how `emplace_back()` can be used to add elements to a JSON array. Note how the `null` value was
silently converted to a JSON array.
```cpp
--8<-- "examples/emplace_back.cpp"
```
Output:
```json
--8<-- "examples/emplace_back.output"
```
## See also
- [operator+=](operator+=.md) add a value to an array/object
- [push_back](push_back.md) add a value to an array/object
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history
- Since version 2.0.8.
- Returns reference since 3.7.0.
File diff suppressed because one or more lines are too long
-85
View File
@@ -1,85 +0,0 @@
# nlohmann::basic_json::emplace_back
```
template<class... Args>
reference emplace_back(Args&& ... args);
```
Creates a JSON value from the passed parameters `args` to the end of the JSON value. If the function is called on a JSON `null` value, an empty array is created before appending the value created from `args`.
## Template parameters
`Args` : compatible types to create a `basic_json` object
## Iterator invalidation
By adding an element to the end of the array, a reallocation can happen, in which case all iterators (including the [`end()`](https://json.nlohmann.me/api/basic_json/end/index.md) iterator) and all references to the elements are invalidated. Otherwise, only the [`end()`](https://json.nlohmann.me/api/basic_json/end/index.md) iterator is invalidated.
## Parameters
`args` (in) : arguments to forward to a constructor of `basic_json`
## Return value
reference to the inserted element
## Exceptions
Throws [`type_error.311`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error311) when called on a type other than JSON array or `null`; example: `"cannot use emplace_back() with number"`
## Complexity
Amortized constant.
## Examples
Example
The example shows how `emplace_back()` can be used to add elements to a JSON array. Note how the `null` value was silently converted to a JSON array.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json array = {1, 2, 3, 4, 5};
json null;
// print values
std::cout << array << '\n';
std::cout << null << '\n';
// add values
array.emplace_back(6);
null.emplace_back("first");
null.emplace_back(3, "second");
// print values
std::cout << array << '\n';
std::cout << null << '\n';
}
```
Output:
```
[1,2,3,4,5]
null
[1,2,3,4,5,6]
["first",["second","second","second"]]
```
## See also
- [operator+=](https://json.nlohmann.me/api/basic_json/operator%2B%3D/index.md) add a value to an array/object
- [push_back](https://json.nlohmann.me/api/basic_json/push_back/index.md) add a value to an array/object
- [Modifying values](https://json.nlohmann.me/features/modifying_values/index.md) - the article on modifying values
## Version history
- Since version 2.0.8.
- Returns reference since 3.7.0.
-66
View File
@@ -1,66 +0,0 @@
# <small>nlohmann::basic_json::</small>empty
```cpp
bool empty() const noexcept;
```
Checks if a JSON value has no elements (i.e., whether its [`size()`](size.md) is `0`).
## Return value
The return value depends on the different types and is defined as follows:
| Value type | return value |
|------------|----------------------------------------|
| null | `#!cpp true` |
| boolean | `#!cpp false` |
| string | `#!cpp false` |
| number | `#!cpp false` |
| binary | `#!cpp false` |
| object | result of function `object_t::empty()` |
| array | result of function `array_t::empty()` |
## Exception safety
No-throw guarantee: this function never throws exceptions.
## Complexity
Constant, as long as [`array_t`](array_t.md) and [`object_t`](object_t.md) satisfy the
[Container](https://en.cppreference.com/w/cpp/named_req/Container) concept; that is, their `empty()` functions have
constant complexity.
## Possible implementation
```cpp
bool empty() const noexcept
{
return size() == 0;
}
```
## Notes
This function does not return whether a string stored as JSON value is empty -- it returns whether the JSON container
itself is empty which is `#!cpp false` in the case of a string.
## Examples
??? example
The following code uses `empty()` to check if a JSON object contains any elements.
```cpp
--8<-- "examples/empty.cpp"
```
Output:
```json
--8<-- "examples/empty.output"
```
## Version history
- Added in version 1.0.0.
- Extended to return `#!cpp false` for binary types in version 3.8.0.
File diff suppressed because one or more lines are too long
-100
View File
@@ -1,100 +0,0 @@
# nlohmann::basic_json::empty
```
bool empty() const noexcept;
```
Checks if a JSON value has no elements (i.e., whether its [`size()`](https://json.nlohmann.me/api/basic_json/size/index.md) is `0`).
## Return value
The return value depends on the different types and is defined as follows:
| Value type | return value |
| ---------- | -------------------------------------- |
| null | `true` |
| boolean | `false` |
| string | `false` |
| number | `false` |
| binary | `false` |
| object | result of function `object_t::empty()` |
| array | result of function `array_t::empty()` |
## Exception safety
No-throw guarantee: this function never throws exceptions.
## Complexity
Constant, as long as [`array_t`](https://json.nlohmann.me/api/basic_json/array_t/index.md) and [`object_t`](https://json.nlohmann.me/api/basic_json/object_t/index.md) satisfy the [Container](https://en.cppreference.com/w/cpp/named_req/Container) concept; that is, their `empty()` functions have constant complexity.
## Possible implementation
```
bool empty() const noexcept
{
return size() == 0;
}
```
## Notes
This function does not return whether a string stored as JSON value is empty -- it returns whether the JSON container itself is empty which is `false` in the case of a string.
## Examples
Example
The following code uses `empty()` to check if a JSON object contains any elements.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_object_empty(json::value_t::object);
json j_array = {1, 2, 4, 8, 16};
json j_array_empty(json::value_t::array);
json j_string = "Hello, world";
// call empty()
std::cout << std::boolalpha;
std::cout << j_null.empty() << '\n';
std::cout << j_boolean.empty() << '\n';
std::cout << j_number_integer.empty() << '\n';
std::cout << j_number_float.empty() << '\n';
std::cout << j_object.empty() << '\n';
std::cout << j_object_empty.empty() << '\n';
std::cout << j_array.empty() << '\n';
std::cout << j_array_empty.empty() << '\n';
std::cout << j_string.empty() << '\n';
}
```
Output:
```
true
false
false
false
false
true
false
true
false
```
## Version history
- Added in version 1.0.0.
- Extended to return `false` for binary types in version 3.8.0.
-42
View File
@@ -1,42 +0,0 @@
# <small>nlohmann::basic_json::</small>end
```cpp
iterator end() noexcept;
const_iterator end() const noexcept;
```
Returns an iterator to one past the last element.
![Illustration from cppreference.com](../../images/range-begin-end.svg)
## Return value
iterator one past the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
??? example
The following code shows an example for `end()`.
```cpp
--8<-- "examples/end.cpp"
```
Output:
```json
--8<-- "examples/end.output"
```
## Version history
- Added in version 1.0.0.
File diff suppressed because one or more lines are too long
-58
View File
@@ -1,58 +0,0 @@
# nlohmann::basic_json::end
```
iterator end() noexcept;
const_iterator end() const noexcept;
```
Returns an iterator to one past the last element.
## Return value
iterator one past the last element
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Examples
Example
The following code shows an example for `end()`.
```
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create an array value
json array = {1, 2, 3, 4, 5};
// get an iterator to one past the last element
json::iterator it = array.end();
// decrement the iterator to point to the last element
--it;
// serialize the element that the iterator points to
std::cout << *it << '\n';
}
```
Output:
```
5
```
## Version history
- Added in version 1.0.0.
-68
View File
@@ -1,68 +0,0 @@
# <small>nlohmann::basic_json::</small>end_pos
```cpp
#if JSON_DIAGNOSTIC_POSITIONS
constexpr std::size_t end_pos() const noexcept;
#endif
```
Returns the position immediately following the last character of the JSON string from which the value was parsed from.
| JSON type | return value |
|-----------|-----------------------------------|
| object | position after the closing `}` |
| array | position after the closing `]` |
| string | position after the closing `"` |
| number | position after the last character |
| boolean | position after `e` |
| null | position after `l` |
## Return value
the position of the character _following_ the last character of the given value in the parsed JSON string, if the
value was created by the [`parse`](parse.md) function, or `std::string::npos` if the value was constructed otherwise
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Notes
!!! note "Note"
The function is only available if macro [`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) has
been defined to `#!cpp 1` before including the library header.
!!! warning "Invalidation"
The returned positions are only valid as long as the JSON value is not changed. The positions are *not* updated
when the JSON value is changed.
## Examples
??? example "Example"
```cpp
--8<-- "examples/diagnostic_positions.cpp"
```
Output:
```
--8<-- "examples/diagnostic_positions.output"
```
The output shows the start/end positions of all the objects and fields in the JSON string.
## See also
- [start_pos](start_pos.md) to access the start position
- [JSON_DIAGNOSTIC_POSITIONS](../macros/json_diagnostic_positions.md) for an overview of the diagnostic positions
## Version history
- Added in version 3.12.0.
File diff suppressed because one or more lines are too long
-163
View File
@@ -1,163 +0,0 @@
# nlohmann::basic_json::end_pos
```
#if JSON_DIAGNOSTIC_POSITIONS
constexpr std::size_t end_pos() const noexcept;
#endif
```
Returns the position immediately following the last character of the JSON string from which the value was parsed from.
| JSON type | return value |
| --------- | --------------------------------- |
| object | position after the closing `}` |
| array | position after the closing `]` |
| string | position after the closing `"` |
| number | position after the last character |
| boolean | position after `e` |
| null | position after `l` |
## Return value
the position of the character *following* the last character of the given value in the parsed JSON string, if the value was created by the [`parse`](https://json.nlohmann.me/api/basic_json/parse/index.md) function, or `std::string::npos` if the value was constructed otherwise
## Exception safety
No-throw guarantee: this member function never throws exceptions.
## Complexity
Constant.
## Notes
Note
The function is only available if macro [`JSON_DIAGNOSTIC_POSITIONS`](https://json.nlohmann.me/api/macros/json_diagnostic_positions/index.md) has been defined to `1` before including the library header.
Invalidation
The returned positions are only valid as long as the JSON value is not changed. The positions are *not* updated when the JSON value is changed.
## Examples
Example
```
#include <iostream>
#define JSON_DIAGNOSTIC_POSITIONS 1
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::string json_string = R"(
{
"address": {
"street": "Fake Street",
"housenumber": 1
}
}
)";
json j = json::parse(json_string);
std::cout << "Root diagnostic positions: \n";
std::cout << "\tstart_pos: " << j.start_pos() << '\n';
std::cout << "\tend_pos:" << j.end_pos() << "\n";
std::cout << "Original string: \n";
std::cout << "{\n \"address\": {\n \"street\": \"Fake Street\",\n \"housenumber\": 1\n }\n }" << "\n";
std::cout << "Parsed string: \n";
std::cout << json_string.substr(j.start_pos(), j.end_pos() - j.start_pos()) << "\n\n";
std::cout << "address diagnostic positions: \n";
std::cout << "\tstart_pos:" << j["address"].start_pos() << '\n';
std::cout << "\tend_pos:" << j["address"].end_pos() << "\n\n";
std::cout << "Original string: \n";
std::cout << "{ \"street\": \"Fake Street\",\n \"housenumber\": 1\n }" << "\n";
std::cout << "Parsed string: \n";
std::cout << json_string.substr(j["address"].start_pos(), j["address"].end_pos() - j["address"].start_pos()) << "\n\n";
std::cout << "street diagnostic positions: \n";
std::cout << "\tstart_pos:" << j["address"]["street"].start_pos() << '\n';
std::cout << "\tend_pos:" << j["address"]["street"].end_pos() << "\n\n";
std::cout << "Original string: \n";
std::cout << "\"Fake Street\"" << "\n";
std::cout << "Parsed string: \n";
std::cout << json_string.substr(j["address"]["street"].start_pos(), j["address"]["street"].end_pos() - j["address"]["street"].start_pos()) << "\n\n";
std::cout << "housenumber diagnostic positions: \n";
std::cout << "\tstart_pos:" << j["address"]["housenumber"].start_pos() << '\n';
std::cout << "\tend_pos:" << j["address"]["housenumber"].end_pos() << "\n\n";
std::cout << "Original string: \n";
std::cout << "1" << "\n";
std::cout << "Parsed string: \n";
std::cout << json_string.substr(j["address"]["housenumber"].start_pos(), j["address"]["housenumber"].end_pos() - j["address"]["housenumber"].start_pos()) << "\n\n";
}
```
Output:
```
Root diagnostic positions:
start_pos: 5
end_pos:109
Original string:
{
"address": {
"street": "Fake Street",
"housenumber": 1
}
}
Parsed string:
{
"address": {
"street": "Fake Street",
"housenumber": 1
}
}
address diagnostic positions:
start_pos:26
end_pos:103
Original string:
{ "street": "Fake Street",
"housenumber": 1
}
Parsed string:
{
"street": "Fake Street",
"housenumber": 1
}
street diagnostic positions:
start_pos:50
end_pos:63
Original string:
"Fake Street"
Parsed string:
"Fake Street"
housenumber diagnostic positions:
start_pos:92
end_pos:93
Original string:
1
Parsed string:
1
```
The output shows the start/end positions of all the objects and fields in the JSON string.
## See also
- [start_pos](https://json.nlohmann.me/api/basic_json/start_pos/index.md) to access the start position
- [JSON_DIAGNOSTIC_POSITIONS](https://json.nlohmann.me/api/macros/json_diagnostic_positions/index.md) for an overview of the diagnostic positions
## Version history
- Added in version 3.12.0.

Some files were not shown because too many files have changed in this diff Show More