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 andconstobjects are still copied. Seebasic_json.
API changes¶
Added (90 pages):
basic_json:as_base_class,format_as(basic_json),from_bon8,merge_diff,basic_json>,to_bon8,with_tbasic_json_document: (overview),accept,basic_json_document,erase,insert,is_discarded,load,memory_usage,node_count,owns_source,parse,parse_copy,push_back,read,root,save,set,shrink_to_fit,sourcebasic_json_view: (overview),at,back,basic_json_view,begin,cbegin,cend,contains,count,dump,empty,end,find,front,get,get_string,get_to,is_array,is_binary,is_boolean,is_discarded,is_null,is_number,is_number_float,is_number_integer,is_number_unsigned,is_object,is_primitive,is_string,is_structured,items,materialize,number_format,number_token,operator[],operator==,operator<<,operator!=,size,source_offset,type,type_name,valuejson_pointer:front,pop_front,push_frontmacros:JSON_BRACE_INIT_COPY_SEMANTICS,JSON_DELETE_DEPRECATED_FUNCTIONS,JSON_DISABLE_STREAM_BULK_SCAN,JSON_DISABLE_TUPLE_REFERENCE_CONVERSION,JSON_DISABLE_UNLOCKED_FILE_IO,JSON_HAS_RANGE_VIEW_CONVERSION,JSON_HAS_STD_FORMAT,JSON_NO_AUTOMATIC_UDLS,JSON_NO_SIMD,JSON_NO_THREAD_LOCAL,JSON_PRECISE_STREAM_POSITION,JSON_STRICT_BINARY_UTF8,JSON_STRICT_NUL_HANDLING,JSON_USE_OBJECTS_FOR_ENUM_KEYED_MAPS,JSON_USE_SIMDUTF,JSON_VIEW_NO_SIMD,JSON_VIEW_USE_SSSE3,nlohmann_define_type_with_names
Changed:
operator>>(basic_json): Fixed a null pointer dereference for anstd::istreamwithout a stream buffer (now throwsparse_error.101), and a crash (std::terminate) whenihaseofbitin 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:jis no longer left with a partially parsed value if parsing throws.operator>>(basic_json): Scans the characters in the stream buffer ofiin bulk in version 3.13.0 unreleased; the position ofiafter the call is unchanged (JSON_DISABLE_STREAM_BULK_SCANrestores reading one character at a time).operator""_json: Addedchar8_t*overload in version 3.13.0 unreleased.operator""_json_pointer: Addedchar8_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: Addedignore_trailing_commasin version 3.13.0 unreleased.basic_json::accept: Extended container support (1) to include types with lvalue-only ADLbegin/end(matchingstd::begin/std::endsemantics) 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 anstd::istreamscans the characters in its stream buffer in bulk in version 3.13.0 unreleased (JSON_DISABLE_STREAM_BULK_SCAN).basic_json::accept: Parsing from aFILE*locks the file once instead of once per character in version 3.13.0 unreleased (JSON_DISABLE_UNLOCKED_FILE_IO).basic_json::array_t: Madecapacity()optional, so that array types such asstd::dequecan be used, in version 3.13.0 unreleased.basic_json::at: Overload 3: Support for keys convertible tostd::string_viewadded in version 3.13.0 unreleased, consistently across the lookup functions.basic_json::basic_json: Overload 4: Explicit for different string types ifJSON_USE_IMPLICIT_CONVERSIONSis0since 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: Fixeddump,std::hash, andto_ubjsonfor 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 tostd::string_viewadded 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 tostd::string_viewadded 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 handlerkeepadded 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: forordered_json, the value could previously only be passed as an rvalue; it can now also be passed as an lvalue or aconstlvalue, matching the behavior ofjson.basic_json::erase: Overload 4: Support for keys convertible tostd::string_viewadded in version 3.13.0 unreleased, consistently across the lookup functions.basic_json::error_handler_t: Addedkeep, and made this enumeration apply to the binary readers and writers in addition todump, in version 3.13.0 unreleased.basic_json::find: Overload 2: Support for keys convertible tostd::string_viewadded 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 ADLbegin/end(matchingstd::begin/std::endsemantics) 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::from_bson: Extended container support (1) to include types with lvalue-only ADLbegin/end(matchingstd::begin/std::endsemantics) 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::from_cbor: Extended container support (1) to include types with lvalue-only ADLbegin/end(matchingstd::begin/std::endsemantics) 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::from_msgpack: Extended container support (1) to include types with lvalue-only ADLbegin/end(matchingstd::begin/std::endsemantics) 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::from_ubjson: Extended container support (1) to include types with lvalue-only ADLbegin/end(matchingstd::begin/std::endsemantics) 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::get_to: Added astatic_assertwith a clear message forconstarguments 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, anilistthat 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 whenapply_patchis*thisor refers to a value contained in*this, in version 3.13.0 unreleased.basic_json::number_unsigned_t: Can be the same type asnumber_integer_tsince version 3.13.0 unreleased.basic_json::object_comparator_t: Fixed the fallback todefault_object_comparator_t, which previously failed to compile for object types without akey_comparemember type, in version 3.13.0 unreleased.basic_json::object_t: Allowed object types whoseerase(iterator)returnsvoidin version 3.13.0 unreleased.basic_json::operator[]: Overload 1: Fixed in version 3.13.0 unreleased to throwstd::length_errorinstead of emptying the array and accessing it out of bounds whenidxequals the maximum value ofsize_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 tostd::string_viewadded 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 conditionallynoexceptin version 3.13.0 unreleased; before, a throwing conversion calledstd::terminate.basic_json::operator>=: Overload 2: Made conditionallynoexceptin version 3.13.0 unreleased; before, a throwing conversion calledstd::terminate.basic_json::operator>: Overload 2: Made conditionallynoexceptin version 3.13.0 unreleased; before, a throwing conversion calledstd::terminate.basic_json::operator<=: Overload 2: Made conditionallynoexceptin version 3.13.0 unreleased; before, a throwing conversion calledstd::terminate.basic_json::operator<: Overload 2: Made conditionallynoexceptin version 3.13.0 unreleased; before, a throwing conversion calledstd::terminate.basic_json::operator!=: Overload 1: Changed in version 3.13.0 unreleased to remove special-casing forNaNanddiscardedvalues;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 rewritesa != busingoperator==.basic_json::operator!=: Overload 2: Changed in version 3.13.0 unreleased to remove special-casing forNaNanddiscardedvalues;operator!=now consistently means!(a == b).basic_json::operator!=: Overload 2: Made conditionallynoexceptin version 3.13.0 unreleased; before, a throwing conversion calledstd::terminate.basic_json::operator<=>: Overload 2: Made conditionallynoexceptin version 3.13.0 unreleased; before, a throwing conversion calledstd::terminate.basic_json::parse: Addedignore_trailing_commasin version 3.13.0 unreleased.basic_json::parse: Extended container support (1) to include types with lvalue-only ADLbegin/end(matchingstd::begin/std::endsemantics) 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 anstd::istreamwithout a stream buffer, and fixed a crash (std::terminate) when parsing from anstd::istreamwitheofbitin its exception mask, in version 3.13.0 unreleased.basic_json::parse: Parsing from anstd::istreamscans the characters in its stream buffer in bulk in version 3.13.0 unreleased (JSON_DISABLE_STREAM_BULK_SCANrestores reading one character at a time).basic_json::parse: Parsing from aFILE*locks the file once instead of once per character in version 3.13.0 unreleased (JSON_DISABLE_UNLOCKED_FILE_IOrestoresstd::fgetc).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: Addedout_of_range.411and 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: Addedout_of_range.413and 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: Addedout_of_range.414and 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: Throwsparse_error.109instead ofout_of_range.404for 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: Addedout_of_range.411and 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: Addedout_of_range.413and 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: Addedout_of_range.414and 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: Throwsparse_error.109instead ofout_of_range.404for 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::sax_parse: Addedignore_trailing_commasin version 3.13.0 unreleased.basic_json::sax_parse: Addedtag_handlerin version 3.13.0 unreleased.basic_json::sax_parse: Extended container support (1) to include types with lvalue-only ADLbegin/end(matchingstd::begin/std::endsemantics) 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_POSITIONadded in version 3.13.0 unreleased to optionally leave astd::istreampositioned right after the parsed value whenstrictisfalse.basic_json::sax_parse: Parsing from anstd::istreamscans 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 aFILE*locks the file once instead of once per character in version 3.13.0 unreleased (JSON_DISABLE_UNLOCKED_FILE_IO).std::hash<nlohmann::basic_json>: Numbers that compare equal hash equally since version 3.13.0 unreleased; before,0,0U, and0.0had different hash values.basic_json::string_t: Removed the requirement thatstring_tbe implicitly convertible fromstd::string, which the BSON writer and the UBJSON reader relied on, in version 3.13.0 unreleased.basic_json::swap: Overload 1: Exchanges thejson_base_class_tsubobject along with the value since version 3.13.0 unreleased.basic_json::swap: Overload 2: Exchanges thejson_base_class_tsubobject along with the value since version 3.13.0 unreleased.basic_json::to_bjdata: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::to_bjdata: Throwstype_error.321for 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: Throwsout_of_range.412andout_of_range.415since version 3.13.0 unreleased.basic_json::to_bson: Linear in the size ofj, 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.415is now detected before anything is written, like the other exceptions above, since version 3.13.0 unreleased.basic_json::to_bson: Throwstype_error.321for a discarded value nested injsince 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::to_bson: Throwsout_of_range.407for 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::to_cbor: Throwstype_error.321for 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: Throwsout_of_range.407for 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: Throwsout_of_range.412andout_of_range.415since version 3.13.0 unreleased.basic_json::to_msgpack: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::to_msgpack: Fixed in version 3.13.0 unreleased to serializenumber_integer_t/number_unsigned_tpairs of different width correctly; before, integers could be serialized with the wrong value ifnumber_integer_twas narrower thannumber_unsigned_t.basic_json::to_msgpack: Throwstype_error.321for 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: Throwsout_of_range.407for 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: Addederror_handlerparameter in version 3.13.0 unreleased.basic_json::to_ubjson: Throwstype_error.321for 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: Throwsparse_error.109instead ofout_of_range.404for 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::update: Fixed use of freed or relocated memory when the argument is*thisor 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 tostd::string_viewadded 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: Throwsparse_error.109instead of returningdefault_valuefor 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_HAS_CPP_11, JSON_HAS_CPP_14, JSON_HAS_CPP_17, JSON_HAS_CPP_20, JSON_HAS_CPP_23, JSON_HAS_CPP_26: AddedJSON_HAS_CPP_26in 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 betweenbasic_jsonspecializations 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 yieldedfalseinstead oftrue.