Files
json/home/releases/unreleased/index.md
T
2026-11-23 07:36:57 +00:00

43 KiB

Unreleased

These changes are part of the develop branch, but not of a release yet.

  • Converting an rvalue container to JSON (json j = std::move(vec);, json j = std::map<std::string, std::string>{...};) now moves the elements instead of copying them (e.g., std::vector<std::string> with 100,000 strings: 4.7 ms to 2.3 ms). Two consequences: the source container is left in a valid but unspecified (moved-from) state, and if an exception is thrown during the conversion, the source may be partially moved-from, so the strong exception guarantee no longer holds for the source of an rvalue conversion (the JSON value itself is unaffected). Lvalues and const objects are still copied, and so are non-owning ranges such as spans (a range whose elements stay mutable through a const range): converting an rvalue span leaves the referenced elements unchanged. See basic_json.
  • In C++20 (library support for char8_t, __cpp_lib_char8_t), a std::u8string is a JSON string: json j = std::u8string(u8"abc"); stores "abc", and j.get<std::u8string>() reads it back. Version 3.12.0 stored a std::u8string as an array of code units ([97,98,99]); on the 3.13.0 development branch it was already stored as a string if std::filesystem is available, but could not be read back. Now the result no longer depends on whether std::filesystem::path is supported, and get<std::u8string>() accepts both a JSON string and the array of numbers written by 3.12.0. Consequence: JSON documents produced from a std::u8string by 3.12.0 (arrays) are still read, but code that checks is_array() on such a value, or that reads it as std::vector<char8_t> / std::vector<std::uint8_t>, now sees a string; to keep the array form, convert explicitly, e.g., json(std::vector<char8_t>(s.begin(), s.end())). std::u8string_view and char8_t arrays are unchanged (arrays of code units). See basic_json.

API changes

Added (90 pages):

Changed:

  • operator>>(basic_json): Fixed a null pointer dereference for an std::istream without a stream buffer (now throws parse_error.101), and a crash (std::terminate) when i has eofbit in its exception mask, in version 3.13.0 unreleased.
  • operator>>(basic_json): Changed to the strong exception safety guarantee in version 3.13.0 unreleased: j is no longer left with a partially parsed value if parsing throws.
  • operator>>(basic_json): Scans the characters in the stream buffer of i in bulk in version 3.13.0 unreleased; the position of i after the call is unchanged (JSON_DISABLE_STREAM_BULK_SCAN restores reading one character at a time).
  • operator""_json: Added char8_t* overload in version 3.13.0 unreleased.
  • operator""_json_pointer: Added char8_t* overload in version 3.13.0 unreleased.
  • ordered_map: Changed in version 3.13.0 unreleased: growing the storage moves the mapped values instead of copying them.
  • basic_json::accept: Added ignore_trailing_commas in version 3.13.0 unreleased.
  • basic_json::accept: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::accept: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::accept: Parsing from an std::istream scans the characters in its stream buffer in bulk in version 3.13.0 unreleased (JSON_DISABLE_STREAM_BULK_SCAN).
  • basic_json::accept: Parsing from a FILE* locks the file once instead of once per character in version 3.13.0 unreleased (JSON_DISABLE_UNLOCKED_FILE_IO).
  • basic_json::accept: Ill-formed UTF-16 and UTF-32 input (a lone surrogate, a high surrogate that is not followed by its low surrogate, or a code point above U+10FFFF) is rejected in version 3.13.0 unreleased; before that, some such sequences were accepted or ended the input silently.
  • basic_json::array_t: Made capacity() optional, so that array types such as std::deque can be used, in version 3.13.0 unreleased.
  • basic_json::at: Overload 3: Support for keys convertible to std::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.
  • basic_json::basic_json: Overload 4: Explicit for different string types if JSON_USE_IMPLICIT_CONVERSIONS is 0 since version 3.13.0 unreleased.
  • basic_json::basic_json: Overload 7: Fixed in version 3.13.0 unreleased to also check the iterator range for binary values; before, a range that did not cover the whole value (such as (end(), end())) was accepted and the whole binary value was copied, unlike the other primitive types.
  • basic_json::binary_t: Fixed dump, std::hash, and to_ubjson for byte types that are not integers (e.g., std::byte) in version 3.13.0 unreleased.
  • basic_json::clear: Fixed in version 3.13.0 unreleased to also clear the subtype of a binary value; before, the subtype was left unchanged.
  • basic_json::contains: Overload 2: Support for keys convertible to std::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.
  • basic_json::contains: Overload 4: Deleted overloads for integral key types added in version 3.13.0 unreleased to reject such calls at compile time instead of causing undefined behavior at runtime.
  • basic_json::count: Overload 2: Support for keys convertible to std::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.
  • basic_json::count: Overload 3: Deleted overload for integral key types added in version 3.13.0 unreleased to reject such calls at compile time instead of causing undefined behavior at runtime.
  • basic_json::dump: Error handler keep added in version 3.13.0 unreleased.
  • basic_json::dump: Doubles are written with the shortest digits (Żmij instead of Grisu2) since version 3.13.0 unreleased; about 0.1% of doubles are written differently, most of them with fewer digits.
  • basic_json::emplace: Fixed in version 3.13.0 unreleased: for ordered_json, the value could previously only be passed as an rvalue; it can now also be passed as an lvalue or a const lvalue, matching the behavior of json.
  • basic_json::erase: Overload 4: Support for keys convertible to std::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.
  • basic_json::error_handler_t: Added keep, and made this enumeration apply to the binary readers and writers in addition to dump, in version 3.13.0 unreleased.
  • basic_json::find: Overload 2: Support for keys convertible to std::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.
  • basic_json::find: Overload 3: Deleted overloads for integral key types added in version 3.13.0 unreleased to reject such calls at compile time instead of causing undefined behavior at runtime.
  • basic_json::from_bjdata: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::from_bjdata: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::from_bjdata: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::from_bson: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::from_bson: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::from_bson: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::from_cbor: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::from_cbor: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::from_cbor: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::from_msgpack: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::from_msgpack: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::from_msgpack: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::from_ubjson: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::from_ubjson: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::from_ubjson: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::from_ubjson: Report start_array(0) to a SAX handler for an optimized array of type N ([$N#n), whatever its count, in version 3.13.0 unreleased.
  • basic_json::from_ubjson: Limited the total number of elements of optimized arrays of Z, T, and F in one input in version 3.13.0 unreleased; the number of elements per byte can be set with JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE, for example to read files written by version 3.12.0 and earlier that exceed the default.
  • basic_json::get_to: Added a static_assert with a clear message for const arguments in version 3.13.0 unreleased.
  • basic_json::insert: Overload 4: Fixed in version 3.13.0 unreleased to copy the values before inserting; before, an ilist that referred to elements of the array being inserted into could insert wrong values, because the range insert could move from or shift an element before it was copied.
  • basic_json::json_base_class_t: Made a public member type in version 3.13.0 unreleased; it was private before, so it could not be named outside the class.
  • basic_json::merge_patch: Fixed use of freed or relocated memory when apply_patch is *this or refers to a value contained in *this, in version 3.13.0 unreleased.
  • basic_json::number_unsigned_t: Can be the same type as number_integer_t since version 3.13.0 unreleased.
  • basic_json::object_comparator_t: Fixed the fallback to default_object_comparator_t, which previously failed to compile for object types without a key_compare member type, in version 3.13.0 unreleased.
  • basic_json::object_t: Allowed object types whose erase(iterator) returns void in version 3.13.0 unreleased.
  • basic_json::operator[]: Overload 1: Fixed in version 3.13.0 unreleased to throw std::length_error instead of emptying the array and accessing it out of bounds when idx equals the maximum value of size_type.
  • basic_json::operator[]: Overload 1: A missing index in the const version is guarded by a runtime assertion since version 3.13.0 unreleased.
  • basic_json::operator[]: Overload 3: Support for keys convertible to std::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.
  • basic_json::operator[]: Overload 4: A missing array index in the const version is guarded by a runtime assertion since version 3.13.0 unreleased.
  • basic_json::operator==: Overload 2: Made conditionally noexcept in version 3.13.0 unreleased; before, a throwing conversion called std::terminate.
  • basic_json::operator>=: Overload 2: Made conditionally noexcept in version 3.13.0 unreleased; before, a throwing conversion called std::terminate.
  • basic_json::operator>: Overload 2: Made conditionally noexcept in version 3.13.0 unreleased; before, a throwing conversion called std::terminate.
  • basic_json::operator<=: Overload 2: Made conditionally noexcept in version 3.13.0 unreleased; before, a throwing conversion called std::terminate.
  • basic_json::operator<: Overload 2: Made conditionally noexcept in version 3.13.0 unreleased; before, a throwing conversion called std::terminate.
  • basic_json::operator!=: Overload 1: Changed in version 3.13.0 unreleased to remove special-casing for NaN and discarded values; operator!= now consistently means !(a == b).
  • basic_json::operator!=: Overload 1: Removed the C++20 member function in version 3.13.0 unreleased; since C++20, the compiler rewrites a != b using operator==.
  • basic_json::operator!=: Overload 2: Changed in version 3.13.0 unreleased to remove special-casing for NaN and discarded values; operator!= now consistently means !(a == b).
  • basic_json::operator!=: Overload 2: Made conditionally noexcept in version 3.13.0 unreleased; before, a throwing conversion called std::terminate.
  • basic_json::operator<=>: Overload 2: Made conditionally noexcept in version 3.13.0 unreleased; before, a throwing conversion called std::terminate.
  • basic_json::parse: Added ignore_trailing_commas in version 3.13.0 unreleased.
  • basic_json::parse: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::parse: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::parse: Extended empty-input detection to also cover an std::istream without a stream buffer, and fixed a crash (std::terminate) when parsing from an std::istream with eofbit in its exception mask, in version 3.13.0 unreleased.
  • basic_json::parse: Fixed the position that a parse_error.101 reports for an unexpected number that is followed by a line feed in version 3.13.0 unreleased: for the input 1, line feed, 2, line feed, version 3.12.0 reported "line 2, column 0" and version 3.13.0 unreleased reports "line 2, column 1"; for 1 2 and a line feed, the report was "line 1, column 0" and is now "line 1, column 3".
  • basic_json::parse: Parsing from an std::istream scans the characters in its stream buffer in bulk in version 3.13.0 unreleased (JSON_DISABLE_STREAM_BULK_SCAN restores reading one character at a time).
  • basic_json::parse: Parsing from a FILE* locks the file once instead of once per character in version 3.13.0 unreleased (JSON_DISABLE_UNLOCKED_FILE_IO restores std::fgetc).
  • basic_json::parse: Ill-formed UTF-16 and UTF-32 input (a lone surrogate, a high surrogate that is not followed by its low surrogate, or a code point above U+10FFFF) is rejected with parse_error.101 in version 3.13.0 unreleased; before that, some such sequences were accepted or ended the input silently.
  • basic_json::parser_callback_t: Fixed in version 3.13.0 unreleased to also remove discarded values from a parent object; before, discarding an array or a value stored under an object key left a discarded member behind, which made the parse result serialize to invalid JSON.
  • basic_json::parser_callback_t: Fixed in version 3.13.0 unreleased so that discarding an array or object at its start event also hides its content from the callback, as documented above; before, the callback was still called for the content, and the key of every member of a discarded object was kept in memory until the parse ended.
  • basic_json::patch: Added out_of_range.411 and stopped relying on an internal assertion when an "add" operation's target location has a non-object/non-array parent in version 3.13.0 unreleased.
  • basic_json::patch: This includes a null parent, which was previously silently converted to an object, in version 3.13.0 unreleased.
  • basic_json::patch: Added out_of_range.413 and stopped silently ignoring a "remove" operation whose target location has a non-object/non-array parent in version 3.13.0 unreleased.
  • basic_json::patch: Added out_of_range.414 and rejected a "move" operation whose "from" location is a proper prefix of its "path" location instead of silently producing a corrupted result in version 3.13.0 unreleased.
  • basic_json::patch: Throws parse_error.109 instead of out_of_range.404 for a one-character array index that is not a digit (e.g., /x) in version 3.13.0 unreleased, as it already did for longer ones.
  • basic_json::patch_inplace: Added out_of_range.411 and stopped relying on an internal assertion when an "add" operation's target location has a non-object/non-array parent in version 3.13.0 unreleased.
  • basic_json::patch_inplace: This includes a null parent, which was previously silently converted to an object, in version 3.13.0 unreleased.
  • basic_json::patch_inplace: Added out_of_range.413 and stopped silently ignoring a "remove" operation whose target location has a non-object/non-array parent in version 3.13.0 unreleased.
  • basic_json::patch_inplace: Added out_of_range.414 and rejected a "move" operation whose "from" location is a proper prefix of its "path" location instead of silently producing a corrupted result in version 3.13.0 unreleased.
  • basic_json::patch_inplace: Throws parse_error.109 instead of out_of_range.404 for a one-character array index that is not a digit (e.g., /x) in version 3.13.0 unreleased, as it already did for longer ones.
  • basic_json::patch_inplace: Applying a JSON value as patch to itself (or, with JSON_DIAGNOSTICS, to a value stored inside it) no longer results in undefined behavior in version 3.13.0 unreleased.
  • basic_json::sax_parse: Added ignore_trailing_commas in version 3.13.0 unreleased.
  • basic_json::sax_parse: Added tag_handler in version 3.13.0 unreleased.
  • basic_json::sax_parse: Extended container support (1) to include types with lvalue-only ADL begin/end (matching std::begin/std::end semantics) in version 3.13.0 unreleased.
  • basic_json::sax_parse: Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
  • basic_json::sax_parse: JSON_PRECISE_STREAM_POSITION added in version 3.13.0 unreleased to optionally leave a std::istream positioned right after the parsed value when strict is false.
  • basic_json::sax_parse: Parsing from an std::istream scans the characters in its stream buffer in bulk in version 3.13.0 unreleased (JSON_DISABLE_STREAM_BULK_SCAN).
  • basic_json::sax_parse: Parsing from a FILE* locks the file once instead of once per character in version 3.13.0 unreleased (JSON_DISABLE_UNLOCKED_FILE_IO).
  • basic_json::sax_parse: Ill-formed UTF-16 and UTF-32 input (a lone surrogate, a high surrogate that is not followed by its low surrogate, or a code point above U+10FFFF) is rejected with parse_error.101 in version 3.13.0 unreleased; before that, some such sequences were accepted or ended the input silently.
  • basic_json::start_pos: Fixed in version 3.13.0 unreleased: in version 3.12.0, the start position of a string that contains escape sequences (for example "\n" or "\u00e4") was too large, by the number of bytes the escape sequences add to the source text.
  • std::hash<nlohmann::basic_json>: Numbers that compare equal hash equally since version 3.13.0 unreleased; before, 0, 0U, and 0.0 had different hash values.
  • basic_json::string_t: Removed the requirement that string_t be implicitly convertible from std::string, which the BSON writer and the UBJSON reader relied on, in version 3.13.0 unreleased.
  • basic_json::swap: Overload 1: Exchanges the json_base_class_t subobject along with the value since version 3.13.0 unreleased.
  • basic_json::swap: Overload 2: Exchanges the json_base_class_t subobject along with the value since version 3.13.0 unreleased.
  • basic_json::to_bjdata: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::to_bjdata: Throws type_error.321 for a discarded value since version 3.13.0 unreleased; previously, a discarded value nested in an array or object was silently skipped, producing invalid BJData.
  • basic_json::to_bson: Throws out_of_range.412 and out_of_range.415 since version 3.13.0 unreleased.
  • basic_json::to_bson: Linear in the size of j, and no longer limited by the call stack for deeply nested values, since version 3.13.0 unreleased.
  • basic_json::to_bson: out_of_range.415 is now detected before anything is written, like the other exceptions above, since version 3.13.0 unreleased.
  • basic_json::to_bson: Throws type_error.321 for a discarded value nested in j since version 3.13.0 unreleased; previously, it was silently skipped, producing a document whose declared size did not match what was actually written.
  • basic_json::to_bson: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::to_bson: Throws out_of_range.407 for integers that do not fit 64 bits since version 3.13.0 unreleased; previously, integers of a number type wider than 64 bits were silently truncated.
  • basic_json::to_cbor: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::to_cbor: Throws type_error.321 for a discarded value since version 3.13.0 unreleased; previously, a discarded value nested in an array or object was silently skipped, producing invalid CBOR.
  • basic_json::to_cbor: Throws out_of_range.407 for integers that do not fit 64 bits since version 3.13.0 unreleased; previously, integers of a number type wider than 64 bits were silently truncated.
  • basic_json::to_msgpack: Throws out_of_range.412 and out_of_range.415 since version 3.13.0 unreleased.
  • basic_json::to_msgpack: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::to_msgpack: Fixed in version 3.13.0 unreleased to serialize number_integer_t/number_unsigned_t pairs of different width correctly; before, integers could be serialized with the wrong value if number_integer_t was narrower than number_unsigned_t.
  • basic_json::to_msgpack: Throws type_error.321 for a discarded value since version 3.13.0 unreleased; previously, a discarded value nested in an array or object was silently skipped, producing invalid MessagePack.
  • basic_json::to_msgpack: Throws out_of_range.407 for integers that do not fit 64 bits since version 3.13.0 unreleased; previously, integers of a number type wider than 64 bits were silently truncated.
  • basic_json::to_ubjson: Added error_handler parameter in version 3.13.0 unreleased.
  • basic_json::to_ubjson: Writes arrays of Z, T, or F without the $ type annotation ([#n Z Z ...) once their elements in one call add up to more than 1,048,576, in version 3.13.0 unreleased, so that from_ubjson can read the output back.
  • basic_json::to_ubjson: Throws type_error.321 for a discarded value since version 3.13.0 unreleased; previously, a discarded value nested in an array or object was silently skipped, producing invalid UBJSON.
  • basic_json::type_name: Added "invalid" return value for corrupted JSON values in version 3.13.0 unreleased.
  • basic_json::unflatten: Made the array/object decision independent of the object's iteration order in version 3.13.0 unreleased.
  • basic_json::unflatten: Throws parse_error.109 instead of out_of_range.404 for a one-character array index that is not a digit (e.g., /x) in version 3.13.0 unreleased, as it already did for longer ones.
  • basic_json::unflatten: Throws type_error.313 for a key that is a prefix of an earlier key in version 3.13.0 unreleased; before, an object type that keeps the insertion order (such as ordered_json) silently replaced the nested value.
  • basic_json::update: Fixed use of freed or relocated memory when the argument is *this or refers to a value contained in *this, in version 3.13.0 unreleased.
  • basic_json::value: Overload 1: Deleted overload for integral key types added in version 3.13.0 unreleased to reject such calls at compile time instead of causing undefined behavior at runtime.
  • basic_json::value: Overload 2: Support for keys convertible to std::string_view added in version 3.13.0 unreleased, consistently across the lookup functions.
  • basic_json::value: Overload 3: Extended to work with arrays in version 3.13.0 unreleased.
  • basic_json::value: Overload 3: Throws parse_error.109 instead of returning default_value for a one-character array index that is not a digit (e.g., /x) in version 3.13.0 unreleased, as it already did for longer ones.
  • json_pointer::operator/=: Overload 1: Appending a JSON pointer to itself no longer results in undefined behavior in version 3.13.0 unreleased.
  • JSON_DIAGNOSTIC_POSITIONS: Fixed in version 3.13.0 unreleased: in version 3.12.0, start_pos() of a string that contains escape sequences was too large; it is now the position of the opening ".
  • JSON_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20, JSON_HAS_CPP_23, JSON_HAS_CPP_26: Added JSON_HAS_CPP_26 in version 3.13.0 unreleased.
  • JSON_HAS_RANGES: Added the exclusions for libstdc++ < 11, Clang < 16 with libstdc++, libc++ < 16, and nvcc (CUDA) 12.0.x and 12.1.x in version 3.13.0 unreleased.
  • JSON_USE_IMPLICIT_CONVERSIONS: Also affects the conversion between basic_json specializations with different string types since version 3.13.0 unreleased.
  • JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON: Fixed in version 3.13.0 unreleased so <= and >= also emulate the legacy behavior in C++20 when the JSON value is the right-hand operand of a scalar comparison; before, only the 3-way-comparison-rewritten candidate was found, which yielded false instead of true.