JSON for Modern C++
Release date: 2020-08-06 SHA-256: 7804b38146921d03374549c9e2a5e3acda097814c43caf2b96a0278e58df26e0 (json.hpp), 6bea5877b1541d353bd77bdfbdb2696333ae5ed8f9e8cc22df657192218cad91 (include.zip)
This release fixes two bugs in the features introduced in release 3.9.0. The lexer did not accept consecutive comments, and ordered_json
lacked some functions from json
. All changes are backward-compatible.
:moneybag: Note you can support this project via GitHub sponsors or PayPal.
/* one */ /* two */ []
). #2330 #2332ordered_json
container did not implement the complete interface of basic_json
which broke existing code when json
was replaced by ordered_json
, in particular when trying to call ordered_json::parse
. #2315 #2319 #2331CMAKE_CURRENT_BINARY_DIR
instead of CMAKE_BINARY_DIR
#2318CMAKE_INSTALL_LIBDIR
. #2314-Wimplicit-fallthrough
warning. #2333The following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.basic_json::parse
, basic_json::accept
, basic_json::sax_parse
, basic_json::from_cbor
, basic_json::from_msgpack
, basic_json::from_ubjson
, basic_json::from_bson
) via initializer lists is deprecated. Instead, pass two iterators; for instance, call basic_json::from_cbor(ptr, ptr+len)
instead of basic_json::from_cbor({ptr, len})
.All deprecations are annotated with HEDLEY_DEPRECATED_FOR
to report which function to use instead.
Release date: 2020-07-27 SHA-256: d8089d52d285ef2c5368eb39ae665b39ea464206b1ca674a88a915c0245ff4f0 (json.hpp), 5b9b819aed31626aefe2eace23498cafafc1691890556cd36d2a8002f6905009 (include.zip)
JSON for Modern C++ 3.9.0 is a feature release that adds four long-awaited features, some requested five years ago.
//
and /* */
style comments. Though comments are not officially part of the JSON specification (see here for a discussion), comment support was a frequently requested feature, and its implementation was much less effort than continuously explaining the lack of comment support.nlohmann::ordered_json
as drop-in replacement for nlohmann::json
for this.All changes are backward-compatible. See below the complete list of changes. See the README or the documentation for more information.
:moneybag: Note you can support this project via GitHub sponsors or PayPal.
ignore_comments
to the parse
function will treat //
and /* */
comments like whitespace. #294 #363 #376 #597 #1513 #2061 #2212nlohmann::ordered_json
to preserve insertion order of object keys. ordered_json
is a specialization of basic_json
and can be used wherever json
is used. #106 #424 #543 #660 #727 #952 #1106 #1717 #1817 #2179 #2206 #2258JSON_ImplicitConversions
and preprocessor symbol JSON_USE_IMPLICIT_CONVERSIONS
to switch off implicit conversions. Implicit conversions, though very practical, are also a source of subtle bugs or unexpected behavior and may be switched off by default in future versions. The new options allow to remove implicit conversions now. #958 #1559NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
and NLOHMANN_DEFINE_TYPE_INTRUSIVE
to simplify serialization/deserialization code for user-defined types. #2175 #2225 #2233 #2267 #2280 #2287 #2306 #2313json.exception.out_of_range.407
will no longer occur for integers larger than 9223372036854775807 (LLONG_MAX
). #2297 #2286allow_exceptions
was not respected. #2299 #2298std::hash<nlohmann::basic_json>
with a function that does not allocate memory. #2292 #2285 #2269FetchContent
. #2222JSON_TestDataDirectory
to select directory of previously downloaded test data for situations where Internet access is forbidden during testing. #2189 #2190JSON_ASSERT
macro to control behavior of assert calls. #2242swap
specialization to support C++20. #2176binary()
function in SAX interface. #2282target_include_directories
. #2279Passing iterator pairs or pointer/length pairs to parsing functions (basic_json::parse
, basic_json::accept
, basic_json::sax_parse
, basic_json::from_cbor
, basic_json::from_msgpack
, basic_json::from_ubjson
, basic_json::from_bson
) via initializer lists is deprecated. Instead, pass two iterators; for instance, call basic_json::from_cbor(ptr, ptr+len)
instead of basic_json::from_cbor({ptr, len})
.
The following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.All deprecations are annotated with HEDLEY_DEPRECATED_FOR
to report which function to use instead.
Release date: 2020-06-14 SHA-256: be7bbfbc7c62c35aa6f27dfbdd950384f247dd9f2281b5930bdaa3a6ab95eef7 (json.hpp), 8590fbcc2346a3eefc341935765dd57598022ada1081b425678f0da9a939a3c0 (include.zip)
It has been six months since the last release, and a lot of minor changes and bug fixes have accumulated. Nonetheless, JSON for Modern C++ 3.8.0 is a feature release.
With binary values we greatly extend the support for binary formats such as CBOR, BSON, or MessagePack. By adding a new value type to the JSON class, binary values can be read and written, and even shared between different formats. See the documentation for examples.
Furthermore, we overworked the input adapters; that is, the way input is read by the parsers. Now any container is supported via the LegacyInputIterator
concept. See the documentation for examples. At the same time, we could improve the performance by 3-10%.
All changes are backward-compatible. See below the complete list of changes.
:moneybag: Note you can now support this project via GitHub sponsors or PayPal.
LegacyInputIterator
. The encoding of the input is implicitly derived from the size of the value type: UTF-8 (1 byte), UTF-16 (2 bytes), and UTF-32 (4 bytes) are supported. #1813 #2145 #2174 #2178float
as float
to save space in the serialization (32 bit va. 64 bit). #1719 #2044from_bson
, from_cbor
, from_msgpack
, and from_ubjson
) now properly respect the allow_exceptions=false
parameter. #1715 #2140contains
function for JSON Pointers now returns false
in all cases a syntactically correct JSON Pointer refers to a non-existing value. Previously, an exception was raised if a JSON Pointer referred to an array, but did not consist of a number. #1942 #1982 #2019+
as array index. #1990/-
in the add
operation for arrays. #1983 #2054push_back
. #1971 #2025value()
function with json::value_t type
parameter. #2086 #2104discarded
before. #1972 #2153std::is_pod
usage as it is deprecated in C++20. #1913 #2033 #2109<ciso646>
is deprecated in C++17 and not included if library is compiled with C++17. #2089 .#2115HEDLEY_DEPRECATED_FOR
to indicate deprecated functions to have supporting compilers report which function to use instead.This release deprecates passing iterator pairs or pointer/length pairs to parsing functions (basic_json::parse
, basic_json::accept
, basic_json::sax_parse
, basic_json::from_cbor
, basic_json::from_msgpack
, basic_json::from_ubjson
, basic_json::from_bson
) via initializer lists. Instead, pass two iterators; for instance, call basic_json::from_cbor(ptr, ptr+len)
instead of basic_json::from_cbor({ptr, len})
.
The following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.All deprecations are annotated with HEDLEY_DEPRECATED_FOR
to report which function to use instead.
Release date: 2019-11-17 SHA-256: 3b5d2b8f8282b80557091514d8ab97e27f9574336c804ee666fda673a9b59926 (json.hpp), 87b5884741427220d3a33df1363ae0e8b898099fbc59f1c451113f6732891014 (include.zip)
This release fixes a bug introduced in release 3.7.2 which could yield quadratic complexity in destructor calls. All changes are backward-compatible.
reserve()
calls from the destructor which could lead to quadratic complexity. #1837 #1838This release does not deprecate any functions. As an overview, the following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.Release date: 2019-11-10 SHA-256: 0a65fcbbe1b334d3f45c9498e5ee28c3f3b2428aea98557da4a3ff12f0f14ad6 (json.hpp), 67f69c9a93b7fa0612dc1b6273119d2c560317333581845f358aaa68bff8f087 (include.zip)
Project bad_json_parsers tested how JSON parser libraries react on deeply nested inputs. It turns out that this library segfaulted at a certain nesting depth. This bug was fixed with this release. Now the parsing is only bounded by the available memory. All changes are backward-compatible.
This release does not deprecate any functions. As an overview, the following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.Release date: 2019-11-06 SHA-256: b5ba7228f3c22a882d379e93d08eab4349458ee16fbf45291347994eac7dc7ce (json.hpp), 77b9f54b34e7989e6f402afb516f7ff2830df551c3a36973085e2c7a6b1045fe (include.zip)
This release fixes several small bugs in the library. All changes are backward-compatible.
std::int64_t
minimum value. #1708 #1722contains()
function for JSON Pointers. #1727 #1741std::pair
and std::tuple
to json
. #1805 #1806 #1825 #1826iteration_proxy
. #1797json
to std::valarray
.items()
function can now be used with a custom string type. #1765json_pointer::back
const
. #1764 #1769ubuntu-latest
/GCC 7.4.0 as CI step.JSON_THROW_USER
, JSON_TRY_USER
, and JSON_CATCH_USER
macros to control user-defined exception handling.GLOB
from CMake files. #1779This release does not deprecate any functions. As an overview, the following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.Release date: 2019-07-28 SHA-256: a503214947952b69f0062f572cb74c17582a495767446347ce2e452963fc2ca4 (json.hpp), 541c34438fd54182e9cdc68dd20c898d766713ad6d901fb2c6e28ff1f1e7c10d (include.zip)
This release introduces a few convenience functions and performs a lot of house keeping (bug fixes and small improvements). All changes are backward-compatible.
contains
function to check if a JSON pointer is valid without throwing exceptions, just like its counterpart for object keys. #1600to_string
to allow for generic conversion to strings. #916 #1585emplace_back
function, returning a reference to the added element just like C++17 is introducing this for std::vector
. #1609std::string_view
in the unit tests. #1634 #1639get_to
method to clear existing content before writing. #1511 #1555-Wc++17-extensions
warning. nodiscard
attributes are now only used with Clang when -std=c++17
is used. #1535 #1551GNUInstallDirs
to set library install directories. #1673json
type on the documentation start page. #1616value()
function with respect to type_error.302
exception. #1601JSON_BuildTests
, JSON_Install
, JSON_MultipleHeaders
, JSON_Sanitizer
, JSON_Valgrind
, JSON_NoExceptions
, JSON_Coverage
).JSON_DEPRECATED
, JSON_NODISCARD
, JSON_LIKELY
, JSON_UNLIKELY
, JSON_HAS_CPP_14
, or JSON_HAS_CPP_17
. Functions taking or returning pointers are annotated accordingly when a pointer will not be null.This release does not deprecate any functions. As an overview, the following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.Release date: 2019-03-20 SHA-256: d2eeb25d2e95bffeb08ebb7704cdffd2e8fca7113eba9a0b38d60a5c391ea09a (json.hpp), 69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf (include.zip)
This release fixes a regression and a bug introduced by the earlier 3.6.0 release. All changes are backward-compatible.
<Windows.h>
was included. #1531This release does not deprecate any functions. As an overview, the following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.Release date: 2019-03-20 SHA-256: ce9839370f28094c71107c405affb3b08c4a098154988014cbb0800b1c44a831 (json.hpp), 237c5e66e7f8186a02804ce9dbd5f69ce89fe7424ef84adf6142e973bd9532f4 (include.zip)
ℹ️ This release introduced a regression. Please update to version 3.6.1!
This release adds some convenience functions for JSON Pointers, introduces a contains
function to check if a key is present in an object, and improves the performance of integer serialization. Furthermore, a lot of small bug fixes and improvements have been made. All changes are backward-compatible.
operator/
and operator/=
. JSON Pointers can be inspected with empty
, back
, and parent_pointer
, and manipulated with push_back
and pop_back
. #1434contains
to check whether an element exists in a JSON object with a given key. Returns false when called on non-object types. #1471 #1474JSON_Install
to control whether the library should be installed (default: on). #1330nodiscard
attribute to meta()
, array()
, object()
, from_cbor
, from_msgpack
, from_ubjson
, from_bson
, and parse
. #1433This release does not deprecate any functions. As an overview, the following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.Release date: 2018-12-22 SHA-256: 8a6dbf3bf01156f438d0ca7e78c2971bca50eec4ca6f0cf59adf3464c43bb9d5 (json.hpp), 3564da9c5b0cf2e032f97c69baedf10ddbc98030c337d0327a215ea72259ea21 (include.zip)
This release introduces the support for structured bindings and reading from FILE*
. Besides, a few bugs have been fixed. All changes are backward-compatible.
Structured bindings are now supported for JSON objects and arrays via the items()
member function, so finally this code is possible:
for (auto& [key, val] : j.items()) {
std::cout << key << ':' << val << '\n';
}
#1388 #1391
Added support for reading from FILE*
to support situations in which streams are nit available or would require too much RAM. #1370 #1392
eofbit
was not set for input streams when the end of a stream was reached while parsing. #1340 #1343-Wshadow
warning #1346std::snprintf
calls to avoid error in MSVC. #1337This release does not deprecate any functions. As an overview, the following functions have been deprecated in earlier versions and will be removed in the next major version (i.e., 4.0.0):
iterator_wrapper
are deprecated. Please use the member function items()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
and friend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please use friend std::istream& operator>>(std::istream&, basic_json&)
and friend operator<<(std::ostream&, const basic_json&)
instead.