JSON for Modern C++ version 3.10.0 #2937
nlohmann
announced in
Announcements
Replies: 2 comments 2 replies
-
Amazing, thank you so much Niels. I've been waiting for this for, well, over a year ;) I just checked a few hours ago, for the first time in a fews months for a new release, and there wasn't any! Off-topic, but GitHub appears to have revamped the release/discussion voting/reactions UI this very day as well... |
Beta Was this translation helpful? Give feedback.
0 replies
-
Will this be added to NuGet https://www.nuget.org/packages/nlohmann.json/ ? That page is showing 3.9.1 as the latest version. Thank you. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Release date: 2021-08-17
SHA-256: 230f3a03cefd586661ebab577a347c973d97a770afb89e22c52abc3c2a19d0a7 (json.hpp), b5e3bfad07feba218a26a4f809fbb0d1e33450524bf5d7244cabc92cf8178c69 (include.zip)
Summary
JSON for Modern C++ 3.10.0 is the first release for over a year. It contains some new features and a lot of minor changes and bug fixes.
Most notably, it introduces extended diagnostics. By defining
JSON_DIAGNOSTICS
before including thejson.hpp
, a JSON Pointer is added to exceptions which helps to debug issues with object access, array indices, or mismatching types.Another important change behind the curtains is a fully overworked CI which performs a lot of checks for every commit which should allow more frequent releases in the future.
All changes are backward-compatible.
💰 Note you can support this project via GitHub sponsors or PayPal.
✨ New Features
Add extended diagnostics information by adding a JSON Pointer to the exception messages indicating the exact location of a invalid type errors or out-of-bound errors.
Exceptions in the library are thrown in the local context of the JSON value they are detected. This makes detailed diagnostics messages, and hence debugging, difficult. To create better diagnostics messages, each JSON value needs a pointer to its parent value such that a global context (i.e., a path from the root value to the value that lead to the exception) can be created. That global context is then provided as a JSON Pointer.
As this global context comes at the price of storing one additional pointer per JSON value and runtime overhead to maintain the parent relation, extended diagnostics are disabled by default. They can, however, be enabled by defining the preprocessor symbol
JSON_DIAGNOSTICS
to 1 before includingjson.hpp
. See thedocumentation
for more information. Add Key name to Exception #932 How to get position info or parser context with custom from_json() that may throw exceptions? #1508 Better diagnostics #2562 Assertion failure when inserting into arrays with JSON_DIAGNOSTICS set #2838 Fix assertion failure in diagnostics #2866Add a GDB pretty printer to facilitate reading
basic_json
values in GDB. GDB pretty printing support #1952 Add GDB pretty printer #2607Add a new value
store
to the cbor_tag_handler_t which allows to store the tags of CBOR values as binary subtypes. Binary subtype field cannot represent all CBOR tags #2863 Fix binary subtypes #2908Add support for containers with non-default-constructible types. Deserialization to std::array with non-default constructable types fails #2574 Add support for deserialization of STL containers of non-default constructable types (fixes #2574). #2576
🐛 Bug Fixes
ordered_json
to be used when exceptions were switched off. Fix code to work without exceptions #2347-fno-expection
not respected anymore in 3.9.1 #2725 Latest version 3.9.1 uses throw instead of JSON_THROW in the amalgamated json.hpp file #2934ordered_json
. Missing "void insert( InputIt first, InputIt last );" overload in nlohmann::ordered_map #2490 Ranged insert test section is added in unit-ordered_json.cpp #2512std::uint64_t
to support subtypes >255. Furthermore, the return value of thesubtype()
function has been fixed to the documented value-1
in case no subtype is given. Binary subtype field cannot represent all CBOR tags #2863 Fix binary subtypes #2908json_ref
type which creatednull
values when compiled with-fno-elide-constructors
. Usage with -fno-elide-constructors causes dump() output to be array ofnull
s #2387 Fix move constructor of json_ref #2405input_adapter
for containers in edge cases. Fix compilation of input_adapter(container) in edge cases #2553std::byte
containers. Compilation failure of tests with C++20 standard (caused by change of u8 literals) #2413 Should it support parsing containers of `std::byte`? #2546 Allow parsing from std::byte containers #2550 Parse from byte-vector results in compile error #2602 can't parse std::vector<std::byte> #2869to_json
in case a JSON value is reused. ASAN detects memory leaks #2865 Fix memory leak in to_json #2872EOF
was not found. Undefined symbol EOF #2755 replace EOF with std::char_traits<char>::eof() #2756NLOHMANN_JSON_SERIALIZE_ENUM
withordered_json
on libc++. Compilation error when using NLOHMANN_JSON_SERIALIZE_ENUM ordered_json on libc++ #2491 Properly constrain the basic_json conversion operator #2825Warnings
A lot of warnings have been fixed in this release. To make sure the library remains warning-free, the CI now breaks in case a warning is found in GCC (261 warning flags), Clang (flag
-Weverything
with 8 exceptions), or MSVC (flag/W4
).-Wimplicit-fallthrough
warnings. Compiler warns of implicit fallthrough when defining preprocessor macro NDEBUG #2348 Remove -Wimplicit-fallthrough warning #2349-Wfloat-equal
warnings. Comparison floating points causes warning #2909 Supress -Wfloat-equal on intended float comparisions #2911exception::what()
to fix C28204 warning. Remove HEDLEY annotation from exception::what() #2673 compile errors .... chromium-style #2680-Wswitch-enum
warnings. All: fix warnings when compiling with -Wswitch-enum #2927/W4
warnings as error. Treat MSVC warnings as errors #2930⚡ Improvements
Tests and CI
The CI chain has been completely overworked and now runs mostly on a dedicated Docker Image that contains all relevant tools.
JSON_CI
.#define private public
hack from test files. Instead, macroJSON_PRIVATE_UNLESS_TESTED
is used in the source code which defaults toprivate
, but can be set topublic
to test internals. Compilation error due to assuming that private=public #43 Don't usedefine private public
in test files #913 Build error: keyword is hidden by macro definition! #1985 Remove "#define private public" from tests #2352CMake
CMAKE_CXX_COMPILER
when the test suite was compiled. fix cmake script overwriting compiler path #2344 Build fails with clang-cl due to override of CMAKE_CXX_COMPILER(?) #2384JSON_BuildTests
andJSON_Install
by default when the library is the main project. Including CTest in the top-level CMakeLists.txt sets BUILD_TESTING=ON for parent projects #2513 Add MAIN_PROJECT check for test and install options #2514not_reproducible
to skip non-reproducible tests. 3.9.0: tests make build non-reproducible #2324 Add switch to skip non-reproducible tests. #2560JSON_SystemInclude
to useSYSTEM
intarget_include_directories
. Add a cmake option to use SYSTEM in target_include_directories #2762JSON_FastTests
(OFF
by default) to which slow test suite.Documentation
is_discarded()
function. json::parse(allow_exceptions = false) documentation is misleading. #2360 Fix and extend documentation of discarded values #2363json::exception::parse_error
#2679using
declarations in README. Consistency withusing
in README.md #2826what()
member function of exception objects unusable in case_HAS_EXCEPTIONS=0
is set. encoding of json::exception::what() #2824Thirdparty
🔨 Further Changes
pkg-config.pc
generation. pkg-config.pc.in: Don't concatenate paths #2690JSON_HAS_CPP_11
,JSON_HAS_CPP_14
,JSON_HAS_CPP_17
, andJSON_HAS_CPP_20
. By defining any of these symbols, the internal check is overridden and the provided C++ version is unconditionally assumed. This can be helpful for compilers that only implement parts of the standard and would be detected incorrectly. Possibility to use with custom c++ version to use in intel sgx enclaves #2730 Fixes #2730 #2731 Update documentation #2749JSON_NO_IO
. When defined, headers<cstdio>
,<ios>
,<iosfwd>
,<istream>
, and<ostream>
are not included and parse functions relying on these headers are excluded. This is relevant for environment where these I/O functions are disallowed for security reasons (e.g., Intel Software Guard Extensions (SGX)). Possibility to use without the dependency to file io and streams to use in intel sgx enclaves #2728 Possibility to use without the dependency to file io and streams to use in intel sgx enclaves #2729 Documentation for macro JSON_NO_IO is missing #2842 Update documentation #2861FetchContent
and require CMake version 3.11. Removed Google Benchmark copy. Fix default branch name for Google Benchmarks. Specified git branch for google benchmark fetch in benchmark test #2795 Failed benchmark due to renamed branch #2796Licensing
is_complete_type
implementation. Clarify license of is_complete_type implementation #2534integer_sequence
andindex_sequence
implementation. License fix #2683🔥 Deprecated functions
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 is deprecated. Instead, pass two iterators; for instance, callbasic_json::from_cbor(ptr, ptr+len)
instead ofbasic_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 functionitems()
instead.friend std::istream& operator<<(basic_json&, std::istream&)
andfriend std::ostream& operator>>(const basic_json&, std::ostream&)
are deprecated. Please usefriend std::istream& operator>>(std::istream&, basic_json&)
andfriend operator<<(std::ostream&, const basic_json&)
instead.All deprecations are annotated with
HEDLEY_DEPRECATED_FOR
to report which function to use instead.This discussion was created from the release JSON for Modern C++ version 3.10.0.
Beta Was this translation helpful? Give feedback.
All reactions