* Make certain usage patterns more prominent in the README
We use this library extensively where I work. After pairing with many
teammates, I've learned that one common stumbling point when using this
library is how to first get a JSON value in the first place (because
once they have a variable of type `json` in hand, the API is intuitive
and mostly does what you expect).
With that in mind, I've added two subsections to the top of the Examples
section: how to read JSON from a file, and how to hardcode a JSON
literal.
I understand that these are already documented elsewhere in the Examples
section, and so these new subsections are technically redundant. But to
defend this choice:
- Redundancy in docs is actually good, because not everyone consumes
docs in the same way or in the same order.
- Having these things called out explicitly in isolation encourages
people to get something working faster. In later sections, these
examples are presented alongside many other options. Having to choose
between alternatives gets in the way of quickly prototyping something.
If you have further suggestions for how to improve or modify these docs
I'm open to them. The changes included here would really make a huge
improvement in the productivity of newer members of my team using this
library.
* Remove old TOC entry
* Put the section back
* Another tweak
* CMake: Add TEST_PROPERTIES to json_test_set_test_options()
Allow overriding test properties via json_test_set_test_options().
* CMake: Set timeouts for Unicode tests
* Add benchmark for cbor serialization and cbor binary data serialization
* Use std::vector::insert method instead of std::copy in output_vector_adapter::write_characters
This change increases a lot the performance when writing lots of binary data.
* Add overloads for more key types to ordered_map
Add overloads to accept additional key types defined by type trait
detail::is_usable_as_key_type to ordered_map.
The same key types that can be used with json can now also be used with
ordered_json.
* Fix ordered_map::erase(first, last) with first == last
* Modify element access unit test to also test ordered_json
Use DOCTEST_* macros in place of predefined compiler macros for compiler
detection and version checks.
The suppression of warning -Wrange-loop-construct in unit-items.cpp
causes GCC<11 to warn about pragmas. Suppressed by adding a version
check.
* Use `std::iterator_traits` to extract `iterator_category`
In third-party STL implementations, `array_t::iterator` might be a pointer (e.g., `vector` in [EASTL](https://github.com/electronicarts/EASTL)) rather than a class, in which case directly using `array_t::iterator::iterator_category` is invalid. This commit fixes it with `std::iterator_traits`, which handles pointers correctly.
* add the changes to the single-header version
* BJData dimension length can not be string_t::npos, fix#3541
* handle error messages on 32bit machine
* add explanation to why size can not be string_t::npos
* add test cases to 32bit unit test
Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
* Fix ndarray dimension signness, fix ndarray length overflow, close#3519
* detect size overflow in ubjson and bjdata
* force reformatting
* Fix MSVC compiler warning
* Add value_in_range_of trait
* Use value_in_range_of trait
* Correct 408 parse_errors to out_of_range
* Add 32bit unit test
The test can be enabled by setting JSON_32bitTest=ON.
* Exclude unreachable lines from coverage
Certain lines are unreachable in 64bit builds.
Co-authored-by: Qianqian Fang <fangqq@gmail.com>
The converting basic_json constructor can inadvertently change the value
type of its parameter. Assert that both basic_json values are of the
same value type after conversion.
* Add C++20 3-way comparison operator and fix broken comparisons
Fixes#3207.
Fixes#3409.
* Fix iterators to meet (more) std::ranges requirements
Fixes#3130.
Related discussion: #3408
* Add note about CMake standard version selection to unit tests
Document how CMake chooses which C++ standard version to use when
building tests.
* Update documentation
* CI: add legacy discarded value comparison
* Fix internal linkage errors when building a module
* Discard optimized containers with negative counts in UBJSON/BJData (#3491,#3492,#3490)
* fix msvc error
* update unit tests for negative sized containers
* use a loop to test 0 ndarray dimension
* throw an error when count is negative, merge CHECK_THROW_AS and _WITH with _WITH_AS
* change bjdata ndarray flag to detect negative size, fix https://github.com/nlohmann/json/issues/3475
* fix CI error
* fix CI on 32bit windows
* remove platform specific out_of_range error messages
* Incorporate suggestions from @nlohmann and @falbrechtskirchinger
* fix CI errors
* add coverage
* fix sax event order
* fix coverage
* ⬆️ Doctest 2.4.7
* 👷 add CI step for ICPC
* 👷 add CI step for ICPC
* 👷 add CI step for ICPC
* ⬇️ downgrade to Doctest 2.4.6
* 👷 add CI step for ICPC
* 👷 add CI step for ICPC
* 👷 add CI step for ICPC
* 👷 add CI step for ICPC
* 👷 add CI step for ICPC
* 🔇 suppress warning #2196: routine is both "inline" and "noinline"
* Re-enable <filesystem> detection on ICPC
* Limit regression test for #3070 to Clang and GCC >=8.4
* Disable deprecation warnings on ICPC
* Disable regression test for #1647 on ICPC (C++20)
* Fix compilation failure of regression test for #3077 on ICPC
* Disable wstring unit test on ICPC
Fixes:
error 913: invalid multibyte character sequence
* Add ICPC to README
Co-authored-by: Niels Lohmann <mail@nlohmann.me>
* Add key_compare member to ordered_map
* Replace == with key_compare in ordered_map
* Expose the actual comparison function used by object_t
nlohmann::ordered_map uses a different comparison function than the one
provided via template parameter.
* Introduce a type trait to detect if object_t has a key_compare member.
* Rename object_comparator_t to default_object_comparator_t.
* Add object_comparator_t to be conditionally defined as
object_t::key_compare, if available, or default_object_comparator_t
otherwise.
* Update the documentation accordingly.
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
* Add type traits to check if a type is usable as object key
Add type trait to check:
* if a type is a specialization of a template.
* if a type is a json_pointer.
* if a type is a basic_json::{const_,}iterator.
* if two types are comparable using a given comparison functor.
* if a type is comparable to basic_json::object_t::key_type.
* if a type has a member type is_transparent.
* if a type is usable as object key.
* if a type has an erase() function accepting a given KeyType.
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
* Rework basic_json element access to accept more key types
Rework basic_json element access member functions and operators to
accept any type that meets the requirements defined by type trait
detail::is_usable_as_key_type.
Member functions and operators:
* at()
* operator[]
* value()
* erase()
* find()
* count()
* contains()
Update documentation to reflect these changes.
Add unit tests to excercise the new functions using std::string_view.
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
* support UBJSON-derived Binary JData (BJData) format
* fix Codacy warning
* partially fix VS compilation errors
* fix additional VS errors
* fix more VS compilation errors
* fix additional warnings and errors for clang and msvc
* add more tests to cover the new bjdata types
* add tests for optimized ndarray, improve coverage, fix clang/gcc warnings
* gcc warn useless conversion but msvc gives an error
* fix ci_test errors
* complete test coverage, fix ci_test errors
* add half precision error test
* fix No newline at end of file error by clang
* simplify endian condition, format unit-bjdata
* remove broken test due to alloc limit
* full coverage, I hope
* move bjdata new markers from default to the same level as ubjson markers
* fix ci errors, add tests for new bjdata switch structure
* make is_bjdata const after using initializer list
* remove the unwanted assert
* move is_bjdata to an optional param to write_ubjson
* pass use_bjdata via output adapter
* revert order to avoid msvc 2015 unreferenced formal param error
* update BJData Spect V1 Draft-2 URL after spec release
* amalgamate code
* code polishing following @gregmarr's feedback
* make use_bjdata a non-default parameter
* fix ci error, remove unwanted param comment
* encode and decode bjdata ndarray in jdata annotations, enable roundtrip tests
* partially fix ci errors, add tests to improve coverage
* polish patch to remove ci errors
* fix a ndarray dim vector condition
* fix clang tidy error
* add sax test cases for ndarray
* add additional sax event tests
* adjust sax event numbering
* fix sax tests
* ndarray can only be used with array containers, discard if used in object
* complete test coverage
* disable [{SHTFNZ in optimized type due to security risks in #2793 and hampered readability
* fix ci error
* move OutputIsLittleEndian from tparam to param to replace use_bjdata
* fix ci clang gcc error
* fix ci static analysis error
* update json_test_data to 3.1.0, enable file-based bjdata unit tests
* fix stack overflow error on msvc 2019 and 2022
* use https link, update sax_parse_error after rebase
* make input_format const and use initializer
* return bool for write_bjdata_ndarray
* test write_bjdata_ndarray return value as boolean
* fix ci error
* Make exception context optional
Change exception context parameter to pointer and replace context with
nullptr where appropriate.
* Support escaping other string types
* Add string concatenation function
Add variadic concat() function for concatenating char *, char, and
string types.
* Replace string concatenations using + with concat()
* Template json_pointer on string type
Change json_pointer from being templated on basic_json to being
templated on string type.
* Add unit test for #3388Closes#3388.
* Fix regression test for #2958
* Add backwards compatibility with json_pointer<basic_json>
* Update json_pointer docs
* Allow comparing different json_pointers
* Update version numbers
Constrain from_json() overload for StringType to not accept json_ref and
require it to be assignable, instead of constructible, from
basic_json::string_t.
Re-enable C++14 tests on Clang <4.0.
Fixes#3171.
Fixes#3267.
Fixes#3312.
Fixes#3384.
* ⬆️ use new CI image
* ⬆️ use new CI image
* 🚨 suppress Clang-Tidy warnings
* 💚 use proper scan-build version
* 🚨 suppress Clang-Tidy warnings
* ⬆️ use more recent GitHub actions
* 💚 add missing compiler
* 📝 update used compilers
* 🚨 fix duplicate inclusion
AppVeyor build VMs should provide at least two cores. Parallelize builds
and tests.
In addition, enable output on failure and disable verbose test output.
Restore the previously disabled check for regression #3070 on all
compilers but MSVC.
To summarize the issue:
Given namespace fs = std::filesystem.
On MSVC attempting to construct an fs::path from json results in an
ambiguous overload resolution because fs::path can be constructed from
both a std::string as well as another fs::path.
To the best of my knowledge there is no way to fix an ambiguous overload
situation involving a type we do not control and with json implicitly
converting to both std::string and fs::path.
Re-enabling the check where it compiles and keeping it disabled for MSVC
is the best we can do.
Closes#3377 and #3382.