Compare commits

..
Author SHA1 Message Date
Niels Lohmann 172eba6e46 docs: cross-link concept pages and API pages in See also sections
Add See also links in both directions between the concept pages (features,
home, integration) and the API pages, write API links in code font, give every
entry a comment after a dash, and show the callback event figure on the parser
callbacks page.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-26 16:17:03 +01:00
Niels Lohmann 02d05057a5 docs: macro chooser generates adl_serializer for non-default-constructible types
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-26 11:17:22 +01:00
Niels Lohmann 444dba381f docs: add figures, table captions and a macro chooser
- Figures with numbered captions: SAX stepper, json_view layout and edit
  stepper, exception map, JSON pointer and patch walkers, QA pipeline,
  scaling and binary size charts, roadmap lanes, release timeline,
  integration decision tree and namespace builder
- Table captions (nj-table-caption) on 9 pages
- Compile times: modules and PCH charts, filesystem section, re-measured
  Figure 1, links between features/modules.md and compile_times.md
- Interactive macro chooser for features/arbitrary_types.md
- Link check: exclude URLs that answer the plugin with 400/401/419 or are
  dead (customers.md)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-26 10:42:00 +01:00
Niels Lohmann 44f1bec789 docs: new design for the documentation site
Apply the brand to the Material for MkDocs site: Inter and JetBrains Mono
served by the site (upright and real italic), brand colours, blue header band
with the syntax pattern, wordmark in the header, new home page (hero, cards,
animated feature tour), 404 page, polish for tabs, search, footer, focus
rings, tables and code blocks, and theme features (code copy, previous/next
footer, TOC follow, search suggestions).

Draw the number railroad diagram, the parser callback events and the iterator
illustrations as inline SVGs that follow the light and dark scheme. The
generator scripts are in docs/mkdocs/scripts/figures; the feature slideshow
(json-light.svg, json-dark.svg, replacing json.gif on the home page) is built
by docs/mkdocs/scripts/slideshow. Decision nodes in five flowcharts become
hexagons, which need far less room.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 20:40:26 +01:00
Niels Lohmann 2a56afc714 Fix VS 2015 build of the DOM parser (#5882) (#5916)
- Name std::hash only once the object type has emplace_new_key: VS 2015
  static-asserts on std::hash of a type without one (alt_string) instead of
  reporting a substitution failure (C2338).
- Replace the std::copy calls on frames by loops: VS 2015 reports raw
  pointers handed to std::copy as C4996, an error under /WX.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 12:08:58 +01:00
Niels Lohmann d176d8d61e Exclude single_include from flawfinder scan (#5912)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 12:08:36 +01:00
Niels Lohmann 1cf5492bcd docs: byte layout sections, glossary entries, and QA page update (#5910)
* docs: byte layout sections, glossary, and QA page updates

- Move "Byte layout" of each binary format to its own section before
  "Serialization" and describe the idea of the format.
- Glossary: add LLDB and other terms used throughout the documentation.
- quality_assurance: correct Clang Static Analyzer and CMake entries; add
  CodeQL, Semgrep, Flawfinder, CIFuzz, OpenSSF Scorecard, REUSE, Meson/SwiftPM,
  and reproducibility checks.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: drop unused length colour from CBOR and MessagePack byte layout legends

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 12:08:14 +01:00
Niels Lohmann 330fbead59 Document clang-tidy exclusions, drop unneeded ones, and clean up doc examples (#5909)
* Document clang-tidy exclusions and drop unneeded ones

Re-enable every excluded check in a run of clang-tidy 22 over all tests
and remove the seven that never fire (cert-err58-cpp,
clang-analyzer-webkit.NoUncountedMemberChecker,
cppcoreguidelines-virtual-class-destructor, google-readability-function-size,
hicpp-function-size, hicpp-no-assembler, readability-function-size).

Document the reason for every remaining exclusion at the top of the file.

Exclude in advance the checks that only exist in clang-tidy 23 and are
noise here (bugprone-signed-bitwise, *-explicit-constructor,
readability-trailing-comma, modernize-use-string-view), plus
modernize-use-integer-sign-comparison, which needs C++20 std::cmp_less
and flags deliberate casts.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix clang-tidy findings in documentation examples and replace redundant aliases

Apply clang-tidy fixes to the documentation examples:
- performance-avoid-endl: std::endl -> '\n'
- readability-qualified-auto: auto -> auto* / const auto*
- performance-for-range-copy: copy -> const reference
- google-readability-casting: C-style cast -> static_cast

Replace redundant aliases (readability-redundant-qualified-alias) such as
"using json = nlohmann::json;" with "using nlohmann::json;" in the
documentation, README, examples, tests, and benchmarks. Aliases at class
scope and aliases of other types (with_base_class_t etc.) are kept.

No changes to the library or its public API. All changed examples were
compiled and run; their output matches the stored .output files (except
max_size and meta, which depend on the platform and compiler).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Format doc examples with the pinned astyle

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 12:07:51 +01:00
Niels Lohmann fe231dc692 docs: write std::chrono durations as unit/value objects; reword a title with escaped quotes (#5911)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 12:07:32 +01:00
Niels Lohmann ffd4242dc2 Docs: fill documentation gaps found in user questions (#5907)
* Docs: fill documentation gaps found in user questions

Add pages on class-hierarchy/smart-pointer/variant/chrono recipes, working
without exceptions, and large, streamed and partial input. Extend the FAQ
(23 entries, Known bugs first), parse error documentation (empty-input
checklist, line/column, diagnostic positions), element access, conversions,
creating values, ADL troubleshooting, memory, and build/distribution notes.
Add 14 examples with generated output. Correct the statement that parse errors
cannot be recovered from with -fno-exceptions.

The topics come from recurring questions on Stack Overflow, Reddit, Hacker
News, YouTube, and the project's GitHub discussions and issues.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: declare range-for lists in variables to keep astyle quiet

astyle reformats a braced init list placed directly in a range-for
header; declare the list first so check_amalgamation passes.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 12:07:13 +01:00
Niels Lohmann cc917d7123 docs: cross-reference json_view and json_document for 3.13.0 (#5892)
* docs: cross-reference json_view and json_document for 3.13.0

Document the new zero-copy document/view API across the docs: add a
"Documents and views" section to the basic_json API hub linking to all
specializations, point parsing/conversion/modifying pages to the view-based
alternatives, add document/view sections to feature pages, update the
landing page to mention json_view.hpp/json_literals.hpp, and cross-link
debugging/exceptions.

Also document wide-string inputs (and ill-formed UTF-16/32 rejection),
add parse/accept examples for wide strings, fix related doc gaps, and
align features/parsing and FAQ with the added support.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: fix article before std::istream in FAQ

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: clarify document inputs, decoding, get<T>() and editing

Address review comments: say which inputs are borrowed and that a wide
string pointer is an extra input, which values are decoded during parsing,
that get<T>() reads only built-in types directly, all forms of set() and
that the document's insert() is array-only, and how to store wide strings.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* docs: integers are converted while parsing a document

Also say "They accept every input" in basic_json_document::parse.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 06:18:07 +01:00
Niels Lohmann 3eae5680d6 from_json: number-first dispatch for arithmetic types, loop for std::array (#5902)
* from_json: number-first dispatch for arithmetic types, loop for std::array (#5891)

from_json(ArithmeticType&) now reads numbers through get_number_value() and
handles a boolean on a cold path, which puts the three number types first in
the per-element type dispatch.

get<std::array<T, N>>() always took the identity_tag overload, a pack
expansion of N calls j.at(i).get<T>() that clang unrolls into straight-line
code (about 28,000 instructions for N = 1000), so its speed depended on
inlining decisions in that body. For trivial element types, which cannot tell
default construction plus assignment from construction in place, it now fills
a std::array in a loop. That loop, shared with get_to(), checks the size once
and reads the inner array directly; a short array still converts the elements
it has and then throws the out_of_range error at() would throw.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Skip the get_to result check without exceptions

Without exceptions, the get_to calls in CHECK_THROWS_WITH_AS do not run,
so the array keeps its initial values (ci_test_noexceptions).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Make is_trivial_element a struct so astyle does not indent it

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Expect the element path in the std::array type-error tests with JSON_DIAGNOSTICS

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Shorten from_json_inplace_array so astyle aligns its parameters

The opening parenthesis of the previous name sat in column 41, beyond
astyle's default --max-continuation-indent of 40, so the continuation
lines fell back to a plain double indent.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Use the compact template<...> style for the new from_json overloads

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 06:17:51 +01:00
Niels Lohmann fe5e401870 Consolidate duplicated detail helpers and bodies (#5891) (#5901)
* Add shared detail helpers for the #5891 cleanup

Add detail::is_primitive(value_t), detail::hex4_lower(), detail::utf8_shape(),
detail::input_format_name(), detail::empty_input_message(), the exception ids
116, 319, 320 and 416 to detail::exception_id, and make
detail::is_ascii_copyable() constexpr. Later commits switch the duplicated
code over to them.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.4: BSON writers share one write-pass UTF-8 sanitizer (#5891)

write_bson_entry_header and write_bson_string re-derived the error-handler
policy differently. Both now use sanitize_utf8_for_bson_write, which treats
strict like keep (the size pass already validated) and sanitizes replace/ignore
into the bytes the size pass measured. No context plumbing is needed.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.1.1: one MessagePack container prefix helper (#5891)

Array and object prefixes differed only in the fix marker and the 16/32-bit
markers; both now delegate to write_msgpack_container_prefix. Output is
byte-identical.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.1.2: one iterative walker for CBOR and MessagePack (#5891)

write_cbor_iterative and write_msgpack_iterative (and their *_value_or_push
helpers) were identical but for the head, scalar, and key writers. They are now
one template over a small policy struct, so everything inlines. BON8 keeps its
own walker (open string run, closing marker), noted in a comment.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.1.3, 2.1.8: one UBJSON container start helper, shared frame base (#5891)

write_ubjson_start_array/_object are now write_ubjson_start_container<IsArray>,
keeping the array-only begin()+1 scan and excessive_valueless rule.
ubjson_frame derives from binary_container_frame instead of duplicating it.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.1.4: write_bytes helper for the byte-string write sites (#5891)

The 13 oa.write_characters(reinterpret_cast<const CharType*>(x.data()), n)
sites now call write_bytes(const void*, size_t); copy_characters sites and the
buffer-based writes are untouched.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.1.5: shared object-key writer for CBOR and MessagePack (#5891)

write_cbor_key and write_msgpack_key were the same SFINAE pair apart from the
string/scalar writers; both now delegate to write_object_key<Walk>. UBJSON key
and to_format_length stay as they are.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.10: writer-side format names from input_format_name (#5891)

The CBOR/MessagePack/UBJSON/BSON/BJData/BON8 literals in throw_on_discarded and
throw_integer_out_of_range calls now come from detail::input_format_name; the
texts are identical, and UBJSON vs BJData still follows use_bjdata.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* serializer: constexpr ascii table, hex4_lower, dedupe helpers (#5891)

1.1: build ascii_copyable() at compile time from is_ascii_copyable and
test find_ascii_copyable_run against it for every byte. 1.2/2.5.4: use
detail::hex4_lower in both \uXXXX writers. 2.1.6: factor the repeated
flush/emit blocks in dump_escaped_impl into always-inline helpers.
2.1.7: comment why the escape copy does not use put_buffer.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.6: use string_t-aware to_string/concat in meta() (#5891)

Replaces the four std::to_string sites; rendered text unchanged.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.7: use detail::is_primitive in json.hpp switches (#5891)

has_no_children, set_parents, max_size and the two diff walkers.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.2.1: factor insert()/iterator throw helpers (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.2.2: share swap() overloads via swap_impl (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.2.4: factor primitive reset and range check in erase()/range ctor (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.2.6: share push_back array bodies via push_back_array_impl (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.2.7: route parse/accept/sax_parse through *_impl helpers (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.2.8: share the vector-returning to_* bodies via to_binary_vector (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.2.10: merge destroy_string/destroy_binary into destroy_pointer (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.4.1/1.7: exceptions: share what_impl, flatten diagnostics switch (#5891)

The four create() bodies build their message through one protected
static helper; the diagnostics parent walk handles array/object and
ignores all other types.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.4.2/2.4.3/1.7: json_pointer: share slash and escape checks, drop primitive case lists (#5891)

The leading-slash and invalid '~' escape checks are shared helpers; the
reference-token walks test object and array first and treat everything
else as primitive.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.7/2.4.9: iter_impl, iteration_proxy: drop primitive case lists, share compare preamble (#5891)

Object and array stay the first branches; everything else is the
primitive case. operator== and operator< share the different-container
check.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.4.5/2.4.6: from_json: share get_number_value and reserve_if_possible (#5891)

The three number cases of get_arithmetic_value and the arithmetic
from_json share one helper (boolean stays accepted only by the latter);
the array and object reserve overload pairs become one.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.4.8: ordered_map: share erase_impl between the key erase overloads (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.7: json_pointer: flatten walk drops the primitive case list (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.2/1.3/1.5/2.5.1/2.5.2/2.5.5: share helpers in the view code (#5891)

- detail::exception_id at every numeric id; throw_* helpers take it
- hex_byte, hex4_lower, utf8_shape replace local hex/table code
- throw_array_index_out_of_range/_past_end, throw_key_not_found
- has_native_float_format replaces the hand-written IEEE check
No change of messages, ids or output.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.5: use utf8_shape in get_bon8_string, add exhaustive UTF-8 validator test (#5891)

get_bon8_string takes the valid range of the second byte from utf8_shape()
(0xF5..0xF7 stay errors, unget behavior unchanged). validate_one_utf8 keeps its
if-chain (hot bulk path); the new test checks decode, validate_one_utf8,
utf8_shape, json::accept and the BON8 reader against each other for every lead
and second byte.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.1: get_cbor_sized_bytes for the CBOR chunk getters (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.2: get_string_with_length for the plain-order string sites (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.3, 2.3.4, 2.3.10: unsupported_key_type, empty_input_message, input_format_name in the readers (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.7, 2.3.9: read_object_key and leave_container_and_check for CBOR/MessagePack/BON8 (#5891)

UBJSON keys (different getter signature) and its container tail stay as is.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.5: json_sax_dom_error_state base for the DOM SAX parsers (#5891)

Holds errored, allow_exceptions, parse_error() and is_errored(). The scalar
handlers stay in each class (parse hot path).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.6: table of control-character messages in the lexer (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.3.8: finish_input helper for the strict-EOF block in the parser (#5891)

sax_parse keeps its if (result) guard and return value. Also adds the
clang-tidy NOLINT for the 2.3.6 message table.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.5.7: share parse_array_index between json_pointer and json_view (#5891)

Move json_pointer::parse_array_index() and its status enum to namespace detail
(json_pointer keeps a forwarding member), and let the json_view pointer
resolution use it instead of its own copy of the RFC 6901 index grammar. Both
accepted the same tokens with the same outcome. Also update the comment on
detail::decode(), which listed four of the five UTF-8 validators and now points
to the test that keeps them in sync.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Amalgamate (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.4.5: keep the inlined number cases in from_json(ArithmeticType&) (#5891)

Calling get_number_value() from from_json(ArithmeticType&) made
GetArray<std::array<int, 1000>> 2.4x slower (it changes the inlining of the
std::array conversion), so that overload keeps its own switch, with a comment.
get_arithmetic_value() still uses the shared helper.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 2.5.7: force-inline detail::parse_array_index (#5891)

Moving parse_array_index out of json_pointer stopped clang from inlining it
into the pointer resolution (JsonPointerAt/citm_catalog +17%,
JsonPointerAt/twitter +8%); JSON_HEDLEY_ALWAYS_INLINE restores the baseline.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* 1.5: keep get_bon8_string's own UTF-8 ranges (#5891)

Taking the second-byte range from utf8_shape() made BON8 decoding 2-3% slower
(FromBinaryShape/scalars, FromBinaryBuffer, alignment-pinned builds), so the byte
path keeps its hand-written ranges. The exhaustive validator test still checks
that it accepts the same sequences as the other validators.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Amalgamate (#5891)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix CI failures: constexpr, NRVO, cppcheck, IWYU (#5891)

- json_sax_dom_error_state::is_errored() cannot be constexpr: the class
  is not a literal type (GCC 4.8, GCC -Wpedantic, Clang 3.5).
- to_binary_vector: destroy the vector writer before returning, as the
  output_vector_sink sets the size of the vector in its destructor.
  Without NRVO (MSVC Debug in C++14 mode), the vector was moved out
  before it was resized.
- parser::sax_parse: return false instead of result after the early exit
  (cppcheck identicalConditionAfterEarlyExit).
- json.hpp: export detail/exceptions.hpp for IWYU, so json_view.hpp can
  name exception_id without including a detail header.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Address review: throw helpers take input_format_t, simpler type checks

- throw_on_discarded() and throw_integer_out_of_range() take an
  input_format_t and call input_format_name() themselves
- has_no_children(), set_parents() and max_size() check array, then
  object, instead of calling is_primitive() first
- parse_impl() chains like accept_impl(); sax_parse_impl() uses if/else
- std::array for the control character messages; negation<> in
  write_object_key(); clarify the is_primitive() comment

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* json_view: use exception_id in the value() overloads

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* json_sax: assert the invariant of place_container for the static analyzer

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-25 06:17:50 +01:00
Niels Lohmann 52b72b5684 Improve documentation: byte layouts, release pages, See also, dark-mode images (#5906)
- Make the iterator range illustrations legible in dark mode (prefers-color-scheme
  rules inside the SVGs).
- Add a "Byte layout" section with a color-coded byte table to each binary format
  page (BJData, BON8, BSON, CBOR, MessagePack, UBJSON), and highlight the smallest
  size per file in the comparison table.
- Add "See also" sections to the overview pages that lacked one.
- Split the release notes into one page per release, grouped by minor version on
  the overview page, with an "API changes" section per release generated from the
  API pages' version histories (hooks/api_changes.py).
- Fact-check the release notes and version histories against the release tags and
  correct wrong or misleading entries (e.g., json_serializer 2.1.0, merge_patch
  3.1.0, items, count, operator[], to_bjdata, std::string_view key support).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-24 17:57:44 +02:00
Niels Lohmann 01139dc192 Silence an Infer false positive in json_view materialize (#5905)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-24 17:10:31 +02:00
Niels Lohmann 9c50bdd140 Make the DOM parser cheaper per container and per member (#5882)
* Reserve the parser's nesting stack once

The stack of open arrays and objects was a std::vector<std::uint8_t> that
allocated at the first push_back and then reallocated at 1, 2, 4, 8 bytes,
so a document nested four levels deep made four allocations before it
parsed a value. A document that starts with a container now reserves 32
levels in one allocation; deeper documents grow as before. The loop that
reads the tokens is the code it was, so large documents are not affected
(a stack object with its own storage, and a reserve at every container,
both cost the token loop instructions or cycles).

Fixed cost of parsing a 124-byte object (macOS instructions): accept
-7.6 %, DOM -2.5 %; no change for a single number.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Build arrays of the DOM parser in one exact-size allocation

Reading an array of unknown length appended its elements to a std::vector
one at a time, so a small array reallocated (and moved its elements) at
sizes 1, 2, 4, ... The DOM SAX parser now collects the elements of arrays
whose length is unknown on one stack shared by all open arrays and moves
them into an array of exactly the right size when the closing bracket
arrives. An array that grows past 16 elements switches to appending to its
own vector, so large arrays pay no second copy. Binary formats, which
announce the length, and builds with JSON_DIAGNOSTICS or
JSON_DIAGNOSTIC_POSITIONS (whose values need their final place from the
start) keep storing into the array directly.

The stacks of open containers are reserved on first use instead of growing
from one element.

The binary readers get a DOM parser of their own, json_sax_dom_binary_parser:
it is the plain parser that stores every value directly in its container
(the code the readers used before). Their containers announce their size, so
the bookkeeping of the collecting parser (frame entries, the destination of a
finished container) was pure overhead for them: with the collecting parser
FromBinaryShape nested was 3-12 % and containers up to 5 % more instructions
(GCC) than before. With the plain parser Linux Ir of FromBinaryShape and
FromBinaryBuffer is within 0.8 % of develop (Clang: identical).

canada.json has 56 000 two-element arrays that took three allocations each
and now take two. DOM parse Ir on Linux against develop (GCC / Clang): canada
-7.0 % / -7.7 %, citm -0.8 % / -1.6 %, 124-byte object -5.4 % / -5.5 %;
accept and SAX are untouched.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Reuse one value for the key events of the callback parser

parse() with a callback built a new string value for every key it passed to
the callback (a heap allocation and release per key), and copied the key a
second time into the object. The callback parser now keeps one string value
for key events, which it assigns, and moves the key into the object.

Callback parse, Linux Ir (GCC / Clang): twitter -13.3 % / -11.7 %, citm
-9.5 % / -7.6 %. (Earlier macOS measurement: twitter -19.5 % instructions.)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Remember where the DOM parser stores the next value

The DOM SAX parser looked up the innermost open container for every value:
the end of its frame stack, then the object or array pointer in the frame.
Compilers have to reload all of that after each value is stored, since a
store of a value may alias the frame. The parser now keeps the innermost
container's kind and, for an array that stores directly, the array itself
in members, updated when a container opens or closes.

Flat arrays of numbers are the case that mattered: parsing floats.json
(1 000 000 doubles) into a DOM took 2 % more cycles than before the
previous commit on macOS and now takes 0.4 % fewer than the code before it
(signed_ints.json -0.8 %). Linux Ir is unchanged (canada -6.1 % GCC /
-6.9 % Clang, citm -0.3 % / -0.8 %, twitter +0.2 % / 0.0 %).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Look up the keys of big ordered_json objects in a hash table

ordered_map keeps its elements in a vector and searches it linearly for
every key it adds, so parsing an object with n keys into ordered_json took
O(n^2) key comparisons: 33 billion instructions for one object with 30 000
keys, where json needs 245 million. From 64 keys on, the DOM parser now
keeps a hash table of the keys of the open object (hashes and positions
only; the elements stay in the vector) and finds duplicate keys there. The
result is the same, including the position of a key that occurs twice.
Smaller objects, std::map based objects and key types without std::hash
are untouched.

ordered_json parse, macOS instructions: object with 1 000 keys 64.8 M ->
14.6 M, 10 000 keys 5 104 M -> 38.7 M, 30 000 keys 33 358 M -> 89 M.
Linux Ir of an object with 2 000 keys: 43.0 M -> 1.9 M (GCC), 37.9 M ->
1.8 M (Clang).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Trim the work the DOM parser does per container and per member

Opening and closing an array or object cost the DOM parser more than before
the exact-size array change, which showed on documents of many small
objects (jeopardy.json: +1.4 % Ir with GCC). This takes it back:

- the stack of open containers keeps its first eight entries in the parser
  object instead of in a vector, so it needs no capacity check beyond the
  push itself and no allocation for typical documents;
- a container is created in the place it ends up in, instead of as a
  temporary that is then moved there;
- a new object member, which is null, is constructed over the null instead
  of being swapped with it (only with the default base class of basic_json);
- the key index that big ordered_json objects use is only a part of the
  stack entries of objects that can have one;
- an array that outgrows the stack reserves twice what it has so far, as a
  vector that grew by itself would have.

DOM parse Ir of the series up to here against develop, Linux GCC / Clang:
canada -6.6 % / -7.3 %, citm +1.2 % / +0.2 %, jeopardy +0.4 % / -0.1 %,
124-byte object -6.5 % / -6.2 %. (twitter measures +6.8 % / +6.6 % at this
point in steady state, almost all of it in glibc's malloc/consolidate for the
new allocation sizes; with the last commit of the series it is -0.1 % / 0.0 %.)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Test parsing containers of the sizes where the DOM parser changes storage

The DOM parser collects the elements of an array on a stack (up to 16) and
the members of an ordered_json object (up to 32) before it moves them into
the container, and uses a hash table for keys from 64 members on. Parse
arrays and objects of the sizes around these limits, nested into each other,
with repeated keys, and as random trees that are built next to their text,
and compare json and ordered_json against the value built through the API.

The tests pass on the code from before these changes as well. The random
trees are what finds the mistakes that are easy to make here: while the
collecting change was being written, a collected array that outgrew the
stack at the moment its parent had just reached the limit left its elements
in the parent, and only these tests (142 failed assertions) showed it.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Do not convert floats that cannot overflow in accept()

accept() only has to find out whether a float token is finite: json_sax_acceptor
ignores the value, and the parser rejects only a float that overflows. A
float whose digits fit into 19 digits and whose decimal exponent is at most
max_exponent10 - 19 is below 10^max_exponent10 and cannot overflow, so the
lexer, told by accept() that the value is not needed, skips the conversion
for those. A token that may overflow, with more digits, or in another float
format is converted as before, so 1e309 and its neighbours are rejected as
they were (the new test compares accept() with parse() on tokens around the
limit).

json::accept(): canada.json Ir -8.6 % (GCC) / -10.9 % (Clang), 124-byte
object -3.2 %; cycles on the M1 (release benchmarks, LTO): canada -7.8 %,
floats.json -9.0 %. The check tests the accept() flag first, so the parser
that needs the value pays one load and branch: SaxParse canada +0.35 % Ir
(GCC and Clang), DOM canada +0.4 %.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Collect the members of ordered_json objects on a stack until they are known

An ordered_json object keeps its members in a vector and appends every new
member to it, so reading an object of unknown size reallocated the vector at
1, 2, 4, 8, ... members, and ordered_map copies all keys on every
reallocation. The DOM SAX parser now collects the members of such objects on
one stack shared by all open objects, as it does the elements of arrays, and
moves them into a vector of exactly the right size when the closing brace
arrives. An object that gets past 32 members switches to appending to its
own vector (and, from 64, to the key index of the earlier commit). The
members are the same, in the same order, and a key that occurs twice keeps
the place of its first occurrence. std::map based objects, objects whose
size the input announces (binary formats), and builds with JSON_DIAGNOSTICS
or JSON_DIAGNOSTIC_POSITIONS are untouched.

What only ordered objects need (the collected members, the key indexes) is
a member of the parser only for them, and the code that stores a value tries
the array that takes its elements directly first. An array that outgrows
the stack now reserves 32 elements, the capacity a vector that grew by
itself has at that point; with the larger reserve before, parsing
floats.json (1 000 000 numbers) was 2 % slower on Apple M1 than before this
series.

ordered_json parse, Linux Ir against develop (GCC / Clang): citm -11.6 % /
-11.7 %, twitter -8.4 % / -8.4 %, jeopardy (12 000 objects of 7 keys)
-10.5 % / -8.0 %, canada -3.9 % / -5.2 %, 124-byte object -20.9 % / -16.5 %.
macOS time (M1, earlier base): citm -19 %, twitter -13 %, jeopardy -13 %,
canada -14 %, 124-byte object -26 %. json parse: steady-state twitter -0.1 %
(see the previous commits), citm -1.2 %.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Rename the key index's match callback so Flawfinder doesn't read it as std::equal

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Bind the parser test's strings by reference in the range-for loop

GCC and Clang 14 (-Wrange-loop-construct) reported the copy.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Collect container values only in basic_json's own parse functions

A json_sax_dom_parser that a user constructs (as in the sax_no_exception
example) must hold the values read before a parse error, as on develop:
its value is used after the error. The values of containers of unknown
size are now collected on a stack only with the new template parameter
Collect (default false), which json::parse() and the json_view
materialization set; without it, every value is stored in place as it
arrives. A test checks the values kept after an error for json and
ordered_json.

Also fixes the clang-tidy, cpplint and Infer findings: the frame stack
keeps its first frames in a std::array (left uninitialized) and the
others in a std::unique_ptr, auto for create<>(), NOLINT for member
initializers -Weffc++ needs, and an @infer-ignore for the nullptr that
place_container() does not use.

json::parse() and ordered_json::parse() instructions are unchanged
(Apple clang; twitter, citm, canada, jeopardy: -0.03 % to +0.25 %).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Clarify the DOM parser's collection stacks and rename reenter_enclosing_container()

Address review comments: explain why a closed container erases only the top
of the shared stack, set the payload before the type, rename the helper that
makes the enclosing container current again, and declare the parser's state
stack right before reserving it.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Export json_sax_dom_parser from the C++20 module for MSVC

MSVC needs the detail classes that basic_json befriends to be visible in
the module (#3970, as json_sax_dom_callback_parser); with its new
template parameter, json_sax_dom_parser failed in ci_module_cpp20
(C2039, not a member of nlohmann::detail).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Keep the overflow-limit numbers of the parser test in a std::vector

clang-tidy (cppcoreguidelines-avoid-c-arrays) rejected the C array.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix the clang-tidy findings of the ordered_json parser tests

The container sizes are a std::array, the expected text uses raw string
literals, the generator's arithmetic is in parentheses, auto for the
result of make<>(), and single characters are appended as characters.
clang-tidy now reports nothing on the lines the branch adds to
unit-ordered_json.cpp and unit-class_parser.cpp (apart from checks CI's
clang-tidy does not have).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-24 07:41:21 +02:00
Niels Lohmann dd7686a269 json_view: faster reading, indexing and C-stream parsing (#5888)
* Read C streams into a json_document in blocks

json_document::parse(FILE*) (and read(), accept(), parse_copy()) went through the
library's file input adapter and appended the text character by character
with fgetc. Read it with fread in blocks instead, like the std::istream
overload already does.

Parsing citm_catalog.json (1.7 MB) from a FILE*:
  Apple M1: 80.6 M -> 8.4 M instructions, 4.8 ms -> 0.55 ms (parse of the same text from a std::string: 8.7 M)
  Linux x86-64 Ir (whole run), GCC 13 / Clang 18: 47.0 M -> 13.7 M / 45.8 M -> 14.2 M
The parsed documents and the error cases are identical (checked over the test corpus
and 30 mutants of each file). A null FILE* is handled as before (by the library's adapter).

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Index arrays without subtrees directly

operator[](idx), at(idx) and back() skipped the elements of an array one
after the other, whatever they were. In an array none of whose elements is
an array or object (numbers, strings, booleans, null) the elements are
adjacent nodes, which the array node's own sizes tell: its subtree has
exactly one node more than it has elements. Such an element is now the
node idx after the array node; any other array is walked as before.

Reading r[i] for every i of an array of 3000 integers:
  Apple M1: 28.8 M instructions, 3.1 ms -> 0.1 M instructions, 4 us
  Linux x86-64 Ir (whole run), GCC 13 / Clang 18: 84.1 M -> 3.1 M / 75.0 M -> 3.0 M
Arrays that contain arrays are unchanged.

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Skip the bounds checks of number and string tokens in NUL-terminated input

For a NUL-terminated input (std::string, C string, string literal), the
parser reads the terminator instead of comparing p with the end, via
cursor::cur(). Number and string scanning still tested `p != e` before each
look at the next byte (after the integer digits for '.', for 'e', after
the exponent sign and digits, and after a string for its closing quote),
although the terminator can never be one of those characters. They now use
cur(), which is the plain load for NUL-terminated input and the bounds check
for ptr+len input, as before.

Parsing, Apple M1 instructions per parse: twitter 3.126 M -> 3.089 M (-1.2 %),
citm_catalog 8.70 M -> 8.58 M (-1.3 %), jeopardy 306.1 M -> 302.5 M (-1.2 %), signed
integers 281 M -> 266 M (-5.4 %), canada and floats -0.1 % / -0.9 %.
Linux x86-64 Ir, GCC 13 / Clang 18: twitter -0.5 % / -0.0 %, signed integers +0.2 % / -0.7 %.

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Make the index text of items() on arrays lazy

basic_json_view::items() on an array formatted every element's index with
std::to_string when the item was made, whether or not the loop asks for the
key. The item now keeps the position and makes the text on the first key()
call. Objects are not affected.

Iterating over the items of an array of 3000 numbers and reading only the values:
  Apple M1: 25.5 us -> 4.6 us (0.45 M -> ~0 net instructions)
  Linux x86-64 Ir (whole run), GCC 13 / Clang 18: 14.9 M -> 4.1 M / 15.3 M -> 4.6 M
Reading key() costs what it did (24.5 us).

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Make the default of value() with a C string only if the member is missing

basic_json_view::value(key, "text") and value(pointer, "text") built a
std::string from the default first and passed it on, so a call allocated
for the default even when the member exists, and copied it again when it
does not. They now look the member up and make the result directly: from the
member if there is one, else from the C string. Behavior, including the
exceptions, is the same.

Two calls (member found, member missing) with a 40 character default, Apple M1:
  1.6 K -> 0.7 K instructions
  Linux x86-64 Ir (500 rounds), GCC 13 / Clang 18: 2.46 M -> 2.22 M / 2.40 M -> 2.15 M

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Materialize scalars directly and keep the stack of small subtrees local

basic_json_view::materialize() (and get<BasicJsonType>()) always set up the
SAX handler that parse() uses and a std::vector for the open containers,
sized from the document's deepest nesting. For a scalar, which is most of what
is materialized one value at a time, neither is needed: the value is made
directly (the same constructors the handler ends up calling). For arrays and
objects the stack of open containers is now a local array for the first 16
levels, and the vector is only used for deeper documents.

Materializing five scalars of a small document, Apple M1: 3.6 K -> 0.9 K instructions
  Linux x86-64 Ir (500 rounds), GCC 13 / Clang 18: 2.96 M -> 2.37 M / 2.90 M -> 2.29 M

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Copy the text between escapes while scanning it

A string that contains an escape is decoded by builder::slow_string(). After
each escape it scanned the next run of plain bytes (8 or 16 byte-by-byte
steps, then a vector loop), and then copied that run to the decode arena in a
second pass. The run is now copied 16 bytes at a time while it is scanned
(one vector load, a store of the same 16 bytes, and the mask of the bytes
that end the run), and the write position lives in a local variable, not in
the builder, since a store of a character may alias the builder's members and
made the compiler reload it after every escape. A run that ends at a quote
needs no scan, and non-ASCII text goes through the UTF-8 check as before;
the portable code is unchanged.

Parsing, Apple M1 instructions: jeopardy.json 304.0 M -> 293.8 M (-3.4 %), 3000 strings with
escapes 1.72 M -> 1.54 M (-10 %), twitter -0.6 %.
Linux x86-64 Ir, GCC 13 / Clang 18: escaped strings -7.6 % / -11.4 %, twitter 0.0 % / 0.0 %.
Documents and error messages are identical on 900 k random strings of escapes, UTF-8 and control
characters (also under ASan), and on mutants of the test corpus.

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Hash the last bytes of a key of a large object without a loop

key_hash() mixed a key eight bytes at a time and then packed the remaining
0-7 bytes one by one, in a loop. The last word of a key of eight or more
bytes is now read as the last eight bytes of the key (overlapping the word
before), and a key of 2-7 bytes as two overlapping words of four or two
bytes. A product only moves bits upwards, and the slot is taken from the low
bits: the high bits of the last word are folded down before the
multiplication, since keys that differ only in their last characters ("user_17",
"user_18") would otherwise share slots. The hash is not stored, so its values
may change.

Looking up every key of an object of 1000 random keys, Apple M1 instructions per 1000 lookups:
  keys of 5 bytes 175 K -> 93 K, hex strings of 8 bytes 177 K -> 168 K, keys of 12 bytes 196 K -> 186 K
Linux x86-64 Ir (whole run), GCC 13 / Clang 18: 5-byte keys -4.7 % / -8.8 %, 12-byte keys -3.3 % / -7.4 %.
Building the tables while parsing such objects is cheaper as well (5-byte keys: 13.3 us -> 10.1 us).

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Compare short keys of a large object without a call of memcmp

find_indexed() compared the key of a member the table points to with
memcmp, a library call for any length. Up to 16 bytes, the bytes are now
compared as two overlapping words (the first and the last 8, 4, or 2 bytes),
as find_member() already does for the objects without a table; longer keys
still use memcmp.

Looking up every key of an object of 1000 random keys, Apple M1 instructions per 1000 lookups
(with the previous commit): keys of 5 bytes 93 K -> 72 K, hex strings of 8 bytes 168 K -> 148 K,
keys of 12 bytes 186 K -> 170 K, keys of 24 bytes 198 K -> 193 K (unchanged, memcmp).
Linux x86-64 Ir (whole run), GCC 13 / Clang 18: 5-byte keys -7.2 % / -7.3 %, 12-byte keys -5.9 % / -6.6 %.

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Read an unedited editable document like a read-only one

Views of a json_editable_document followed edits at every step: the
lookup, the element access, back(), dump() and materialize() were built
for nodes that can be moved or linked, though no edit changes the index until
the first one (every edit creates the edit state before it touches a node).
Until then these now take the read-only code: one check of the document's
edit state per call, not per member or per node. After the first edit
nothing changes. Views that were made earlier keep working, as the check is
made when they are used.

Unedited editable document, Apple M1: dump() of twitter.json 1.40 M -> 1.22 M instructions (-12.6 %);
lookups unchanged. Linux x86-64 Ir, GCC 13 / Clang 18: dump -1.7 % / -1.0 %, lookups -0.1 % / 0.0 %.
Walking with iterators is unchanged, and so is dump() after an edit.

Belongs to the PR "json_view: read-side speedups".

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Format the numbered test keys of json_view's index with a stream

The keys were made with snprintf() and a format from a list, which
Flawfinder reports as an error (CWE-134, a format string that is not a
literal). A stream now formats them; the 30000 keys of the test are the
same as before.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Put the key number of the json_view index test in parentheses

astyle formatted i * step after << as a pointer declaration (i* step),
which failed the amalgamation check.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix the compiler and lint findings of json_view's read side and tests

- find() and contains() dispatch on Editable for the member lookup; for
  documents that cannot be edited both branches were the same call
  (GCC -Wduplicated-branches)
- json_view.hpp includes <cstdio> for the FILE overload (cpplint)
- the arena check macro of the builder is on one line (cpplint read it
  as an if body without braces)
- tests: no nested conditional (also MSVC C4018), no useless cast,
  parentheses around mixed operators, raw string literals, += instead
  of temporary concatenations, and NOLINT for the fixed seeds and a
  find() != npos, as elsewhere in the tests

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Grow the decode arena through a function and store its position back on every return

slow_string() kept its write position in locals and grew the arena through
the macro NLOHMANN_VIEW_ENSURE. The macro is now the always-inline member
arena_ensure() (a lambda is not inlined at every call site by clang, which
then keeps the position in memory: +11 % instructions on escape-heavy
strings), and a guard stores the position back into m_arena_write on every
return instead of by hand on the successful one. Instruction counts are
unchanged (clang) or 1 % lower (GCC).

Also word the complexity of back() as that of at().

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-24 07:41:06 +02:00
Niels Lohmann e9c4fe3cdf json_view: indented and ensure_ascii dumps through the fast writer (#5889)
* Write the indented output of json_view's dump() with the fast writer

The compact writer of dump() (cursor in a register, fixed-size copies of
tokens) served dump(-1) only; every dump(indent), and everything with
ensure_ascii that was indented, went through a generic walk that calls put()
for each token and put_repeated() (a memset call) for each line break. The
fast writer now writes indented output, too, with or without ensure_ascii, and
the generic walk is gone. A line break is a copy of a 64-byte ruler (a line
break and 63 indentation characters) when the line is at most 64 bytes, and a
store plus memset beyond that. The depth is counted only in the indented
instantiations (counting it in the compact one cost an editable document 5 %
with Clang). The indented walks are out of line (dump_pretty()): inlined
into dump() next to the compact ones, they made compact dumps of integer
arrays 7 % slower.

A decoded string (one with escape sequences) of a damaged image loaded with
image_check::bounds can contain invalid UTF-8. As before, the compact dump
writes such bytes unchanged, and the indented dump throws type_error.316; its
runs are found by the lexer's validating scan (a scalar validation of every
sequence made dump(2) of decoded CJK text twice as slow as before).

dump(2) instructions per call, macOS arm64 (before -> after):

               twitter         citm            canada          jeopardy(4k)
  json         3.75M -> 1.85M  8.28M -> 3.93M  67.1M -> 56.0M  9.56M -> 4.81M
  editable     3.82M -> 1.84M  8.48M -> 4.02M  68.1M -> 56.2M  9.66M -> 4.75M

Linux instructions (GCC 13 / Clang 18), dump(2) and dump(2, ' ', true):

  twitter      -25 % / -30 %      -11 % / -11 %
  citm         -29 % / -28 %      -24 % / -24 %
  jeopardy(4k) -25 % / -32 %      -20 % / -24 %
  CJK text with \u escapes  -6 % / -11 %   -2 % / -2 %

The compact dump is unchanged (within +0.4 % on Linux, within noise on the Mac).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Scan the strings of json_view's dump() with ensure_ascii 16 bytes at a time

With ensure_ascii, a string of the source that has a byte >= 0x7F was written
by a generic path: put() per piece and a validate-and-decode step for every
character beyond ASCII. It now goes through a writer with the cursor in a
local variable. The part of the string that has nothing to escape is found
16 bytes at a time (SSE2 or NEON; the existing 8-byte scan without vector
support) and copied; strings that are ASCII throughout are still decided by
the 8-byte check of dump() with ensure_ascii (a 16-byte scan for them was
2-5 % slower for short strings). The two-byte sequences (lead C2..DF) and
the three-byte sequences whose continuation bytes may have any value (lead
E1..EF except ED) are decoded with a few compares; E0, ED, four-byte
sequences, and damaged input go through validate_one_utf8() as before, so
damaged images still throw type_error.316.

dump(-1, ' ', true) instructions per call, macOS arm64 (develop -> now);
the compact dump without ensure_ascii and dumps of ASCII text are unchanged:

  twitter 5.42M -> 3.57M    citm 3.28M -> 3.24M     jeopardy(4k) 5.78M -> 5.65M
  CJK text, raw 66.5M -> 35.3M    escaped \u 32.7M -> 17.0M
  Latin text with accents 11.5M -> 9.4M    ASCII text 4.40M -> 4.40M

Linux instructions (GCC 13 / Clang 18), dump(-1, ' ', true):

  twitter -9 % / -33 %    CJK text -14 % / -47 %    Latin text -8 % / -18 %
  citm -0.2 % / -0.4 %    ASCII text -0.1 % / -0.3 %

The compact dump without ensure_ascii is unchanged (canada 0.0 %).

The unit test covers every character of the Basic Multilingual Plane, and a
character that needs an escape at each position of strings of 0..40 bytes.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Find the end of the plain run of a decoded string 16 bytes at a time with SSE2

The strings of a document that had escape sequences are written in runs
without a quote, backslash, or control character; the compact dump found the
end of a run 8 bytes at a time with a SWAR test. With SSE2 (x86-64) it now
compares 16 bytes per step. NEON keeps the SWAR code: there the mask of a
step costs more than it saves on the short runs that are typical here.

Instructions of dump(), Linux (GCC 13 / Clang 18):

  twitter.json                  1.99M -> 1.88M (-5.2 %) / 1.97M -> 1.92M (-3.0 %)
  CJK text with \u escapes      5.98M -> 4.52M (-24.5 %) / 5.30M -> 4.25M (-19.9 %)
  ASCII text with a few escapes 4.28M -> 4.09M (-4.4 %) / 4.24M -> 4.11M (-3.2 %)
  jeopardy (4,000 questions)    5.08M -> 4.78M (-5.8 %) / 4.97M -> 4.80M (-3.4 %)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Rename depth_counter's open() and close() to enter() and leave()

Flawfinder took them for the file functions open() and close().

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix the clang-tidy findings in json_view's dump and its tests

- the SSE2 loop of the string scan is within NOLINTBEGIN/END
  (portability-simd-intrinsics), as in to_chars.hpp
- depth_counter<false>'s leave() and get() keep the interface of
  depth_counter<true> instead of being static
- write_ascii() compares the room left as a size_t variable
- the test's texts are a std::array, and a JSON fragment with escapes
  is a raw string literal

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Move dump_ascii() and dump_pretty() next to dump()

Address a review comment: the two dispatchers that dump() calls now follow
it directly.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-24 07:38:17 +02:00
dependabot[bot] 1e9222f955 Bump dompurify from 3.4.16 to 3.4.17 in /docs/mkdocs/scripts/mermaid (#5904)
Bumps [dompurify](https://github.com/cure53/DOMPurify) from 3.4.16 to 3.4.17.
- [Release notes](https://github.com/cure53/DOMPurify/releases)
- [Commits](https://github.com/cure53/DOMPurify/compare/3.4.16...3.4.17)

---
updated-dependencies:
- dependency-name: dompurify
  dependency-version: 3.4.17
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-24 07:37:42 +02:00
Niels Lohmann ffcd392be0 Fix Semgrep findings in Python tooling (#5899)
- generate_docset.py: use SHA-256 instead of SHA-1 for the cache file
  name digest of downloaded images.
- generate_docset.py: suppress dynamic-urllib-use-detected; the URL
  scheme is restricted to http(s) right before the call.
- generate_natvis.py: suppress direct-use-of-jinja2; the template
  renders a local XML file with autoescape enabled.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-23 07:11:17 +02:00
905 changed files with 22920 additions and 9619 deletions

No files matched your search

+36 -7
View File
@@ -1,3 +1,33 @@
# Style or vendor rule sets that do not fit a header-only library:
# altera-*, fuchsia-*, llvmlibc-*, android-cloexec-fopen, boost-use-ranges, llvm-header-guard,
# llvm-include-order, llvm-prefer-static-over-anonymous-namespace, llvm-use-ranges,
# misc-use-anonymous-namespace, google-runtime-float, google-runtime-int, hicpp-signed-bitwise,
# bugprone-signed-bitwise, hicpp-explicit-conversions, google-explicit-constructor,
# cppcoreguidelines-explicit-constructor, misc-explicit-constructor (implicit conversions are the
# API), readability-trailing-comma,
# hicpp-avoid-goto / cppcoreguidelines-avoid-goto, hicpp-no-array-decay,
# hicpp-uppercase-literal-suffix, readability-uppercase-literal-suffix, modernize-use-trailing-return-type.
# Constructs the library needs on purpose (the library supports C++11 and legacy compilers):
# cppcoreguidelines-macro-usage, cppcoreguidelines-avoid-do-while (macros),
# cppcoreguidelines-pro-bounds-*, cppcoreguidelines-pro-type-reinterpret-cast,
# cppcoreguidelines-pro-type-union-access (parsers, serializers, basic_json's value union),
# cppcoreguidelines-avoid-const-or-ref-data-members, cppcoreguidelines-rvalue-reference-param-not-moved,
# cppcoreguidelines-avoid-non-const-global-variables, misc-non-private-member-variables-in-classes,
# misc-no-recursion (value walks are recursive, bounded by detail::recursion_depth_limit()),
# modernize-type-traits, modernize-use-constraints, modernize-use-ranges, modernize-use-std-numbers,
# modernize-use-designated-initializers, modernize-use-nodiscard, modernize-concat-nested-namespaces,
# readability-redundant-typename, readability-redundant-parentheses,
# readability-redundant-access-specifiers, readability-simplify-boolean-expr,
# readability-use-concise-preprocessor-directives, modernize-use-string-view,
# modernize-use-integer-sign-comparison (needs std::cmp_less; the flagged
# static_cast<std::size_t>(end - pos) < n comparisons are deliberate)
# (all need a newer standard or compiler than C++11, or would change macro-generated or
# deliberately explicit code).
# Too noisy to be useful (numeric parsing/formatting code, doctest, tests):
# bugprone-easily-swappable-parameters, cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers,
# readability-identifier-length, readability-function-cognitive-complexity, performance-enum-size,
# concurrency-mt-unsafe, misc-confusable-identifiers, misc-include-cleaner (run on its own for
# the consumer headers in cmake/ci.cmake).
# portability-avoid-pragma-once: kept disabled on purpose. #pragma once is accepted # portability-avoid-pragma-once: kept disabled on purpose. #pragma once is accepted
# by every supported compiler, and tools/amalgamate/amalgamate.py strips it from # by every supported compiler, and tools/amalgamate/amalgamate.py strips it from
# single_include, so there is nothing left to fix here. # single_include, so there is nothing left to fix here.
@@ -10,14 +40,14 @@ Checks: '*,
-android-cloexec-fopen, -android-cloexec-fopen,
-boost-use-ranges, -boost-use-ranges,
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
-cert-err58-cpp, -bugprone-signed-bitwise,
-clang-analyzer-webkit.NoUncountedMemberChecker,
-concurrency-mt-unsafe, -concurrency-mt-unsafe,
-cppcoreguidelines-avoid-const-or-ref-data-members, -cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-goto,
-cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-explicit-constructor,
-cppcoreguidelines-macro-usage, -cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access, -cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
@@ -26,19 +56,15 @@ Checks: '*,
-cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-rvalue-reference-param-not-moved, -cppcoreguidelines-rvalue-reference-param-not-moved,
-cppcoreguidelines-virtual-class-destructor,
-fuchsia-default-arguments-calls, -fuchsia-default-arguments-calls,
-fuchsia-default-arguments-declarations, -fuchsia-default-arguments-declarations,
-fuchsia-overloaded-operator, -fuchsia-overloaded-operator,
-google-explicit-constructor, -google-explicit-constructor,
-google-readability-function-size,
-google-runtime-float, -google-runtime-float,
-google-runtime-int, -google-runtime-int,
-hicpp-avoid-goto, -hicpp-avoid-goto,
-hicpp-explicit-conversions, -hicpp-explicit-conversions,
-hicpp-function-size,
-hicpp-no-array-decay, -hicpp-no-array-decay,
-hicpp-no-assembler,
-hicpp-signed-bitwise, -hicpp-signed-bitwise,
-hicpp-uppercase-literal-suffix, -hicpp-uppercase-literal-suffix,
-llvm-header-guard, -llvm-header-guard,
@@ -48,6 +74,7 @@ Checks: '*,
-llvmlibc-*, -llvmlibc-*,
-misc-use-anonymous-namespace, -misc-use-anonymous-namespace,
-misc-confusable-identifiers, -misc-confusable-identifiers,
-misc-explicit-constructor,
-misc-include-cleaner, -misc-include-cleaner,
-misc-no-recursion, -misc-no-recursion,
-misc-non-private-member-variables-in-classes, -misc-non-private-member-variables-in-classes,
@@ -55,20 +82,22 @@ Checks: '*,
-modernize-type-traits, -modernize-type-traits,
-modernize-use-constraints, -modernize-use-constraints,
-modernize-use-designated-initializers, -modernize-use-designated-initializers,
-modernize-use-integer-sign-comparison,
-modernize-use-nodiscard, -modernize-use-nodiscard,
-modernize-use-ranges, -modernize-use-ranges,
-modernize-use-string-view,
-modernize-use-std-numbers, -modernize-use-std-numbers,
-modernize-use-trailing-return-type, -modernize-use-trailing-return-type,
-performance-enum-size, -performance-enum-size,
-portability-avoid-pragma-once, -portability-avoid-pragma-once,
-readability-function-cognitive-complexity, -readability-function-cognitive-complexity,
-readability-function-size,
-readability-identifier-length, -readability-identifier-length,
-readability-magic-numbers, -readability-magic-numbers,
-readability-redundant-access-specifiers, -readability-redundant-access-specifiers,
-readability-redundant-parentheses, -readability-redundant-parentheses,
-readability-redundant-typename, -readability-redundant-typename,
-readability-simplify-boolean-expr, -readability-simplify-boolean-expr,
-readability-trailing-comma,
-readability-uppercase-literal-suffix, -readability-uppercase-literal-suffix,
-readability-use-concise-preprocessor-directives' -readability-use-concise-preprocessor-directives'
+1 -8
View File
@@ -29,13 +29,6 @@ updates:
- dependency-name: mermaid - dependency-name: mermaid
update-types: ["version-update:semver-major"] update-types: ["version-update:semver-major"]
- package-ecosystem: pip
directory: /.github/requirements
schedule:
interval: daily
cooldown:
default-days: 7
- package-ecosystem: pip - package-ecosystem: pip
directory: /tools/astyle directory: /tools/astyle
schedule: schedule:
@@ -43,7 +36,7 @@ updates:
cooldown: cooldown:
default-days: 7 default-days: 7
ignore: ignore:
# astyle is deliberately pinned (see tools/astyle/requirements.in): newer versions # astyle is deliberately pinned (see tools/astyle/requirements.txt): newer versions
# reformat the code, and the pinned version defines the formatting CI enforces # reformat the code, and the pinned version defines the formatting CI enforces
- dependency-name: astyle - dependency-name: astyle
-1
View File
@@ -1 +0,0 @@
meson==1.12.1
-10
View File
@@ -1,10 +0,0 @@
#
# This file is autogenerated by pip-compile with Python 3.14
# by the following command:
#
# pip-compile --generate-hashes --no-emit-index-url --output-file=.github/requirements/meson.txt --strip-extras .github/requirements/meson.in
#
meson==1.12.1 \
--hash=sha256:930bc7542cbd9f57009e182fd014eba48cf1a0180a7b9006d2d32d8f168d8b02 \
--hash=sha256:ab0a6ca09f8ef70c564c8241fb5a23957886a0b53fb58412b5e07eaf07dba743
# via -r .github/requirements/meson.in
-1
View File
@@ -1 +0,0 @@
semgrep==1.182.1
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -67,10 +67,10 @@ jobs:
- name: Install astyle - name: Install astyle
run: | run: |
python3 -mvenv venv python3 -mvenv venv
venv/bin/pip3 install --require-hashes -r $MAIN_DIR/tools/astyle/requirements.txt venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
- name: Install generate_natvis dependencies - name: Install generate_natvis dependencies
run: pip3 install --require-hashes -r $MAIN_DIR/tools/generate_natvis/requirements.txt run: pip3 install -r $NATVIS_TOOL_DIR/requirements.txt
- name: Regenerate the tools/macro_builder tables in macro_scope.hpp - name: Regenerate the tools/macro_builder tables in macro_scope.hpp
run: | run: |
-9
View File
@@ -31,12 +31,3 @@ jobs:
persist-credentials: false persist-credentials: false
- name: 'Dependency Review' - name: 'Dependency Review'
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0 uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
with:
# Semgrep pins mcp==1.29.0 and opentelemetry-api~=1.37.0 exactly
# (.github/requirements/semgrep.txt), so these cannot be upgraded
# until Semgrep lifts its pins. They do not apply to our use: CI
# only runs `semgrep scan` on the checkout and never starts the MCP
# server (GHSA-84m7-p3x7-pcfv, StreamableHTTP sessions) or parses
# incoming trace context (GHSA-xcq7-p3pf-p88h, tracestate parsing).
# Remove the entries once a Semgrep release allows the fixed versions.
allow-ghsas: GHSA-84m7-p3x7-pcfv, GHSA-xcq7-p3pf-p88h
+2 -1
View File
@@ -43,7 +43,8 @@ jobs:
- name: flawfinder_scan - name: flawfinder_scan
uses: david-a-wheeler/flawfinder@c4216b74cf2639ffa98503768bd6e4299b5440c9 # v2.0.20 uses: david-a-wheeler/flawfinder@c4216b74cf2639ffa98503768bd6e4299b5440c9 # v2.0.20
with: with:
arguments: '--sarif ./' # single_include/ is omitted: it is generated from include/ and would report every finding twice
arguments: '--sarif ./cmake ./docs ./include ./src ./tests ./tools'
output: 'flawfinder_results.sarif' output: 'flawfinder_results.sarif'
- name: Upload analysis results to GitHub Security tab - name: Upload analysis results to GitHub Security tab
+1 -1
View File
@@ -53,7 +53,7 @@ jobs:
# SEMGREP_APP_TOKEN is still passed through so registry auth works if a # SEMGREP_APP_TOKEN is still passed through so registry auth works if a
# token is ever added. # token is ever added.
- name: Install Semgrep - name: Install Semgrep
run: python3 -m pip install --user --require-hashes -r .github/requirements/semgrep.txt run: python3 -m pip install --user semgrep==1.168.0
# `semgrep scan --sarif` always exits 0 even with findings; continue-on-error # `semgrep scan --sarif` always exits 0 even with findings; continue-on-error
# is a safety net so the SARIF upload still runs if the scan itself errors. # is a safety net so the SARIF upload still runs if the scan itself errors.
+1 -1
View File
@@ -42,7 +42,7 @@ jobs:
- name: Check that Meson and pkg-config offer the CMake options - name: Check that Meson and pkg-config offer the CMake options
run: make check_build_options run: make check_build_options
- name: Install Meson - name: Install Meson
run: pip install --require-hashes -r .github/requirements/meson.txt run: pip install meson
- name: Install with Meson - name: Install with Meson
run: | run: |
meson setup build-meson --prefix=${{ github.workspace }}/install meson setup build-meson --prefix=${{ github.workspace }}/install
+4 -4
View File
@@ -151,7 +151,7 @@ The `json` class provides an API for manipulating a JSON value. To create a `jso
```cpp ```cpp
#include <fstream> #include <fstream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using json = nlohmann::json; using nlohmann::json;
// ... // ...
@@ -164,7 +164,7 @@ If using modules (enabled with `NLOHMANN_JSON_BUILD_MODULES`), this example beco
import std; import std;
import nlohmann.json; import nlohmann.json;
using json = nlohmann::json; using nlohmann::json;
// ... // ...
@@ -842,7 +842,7 @@ assert(p == p2);
To make this work with one of your types, you only need to provide two functions: To make this work with one of your types, you only need to provide two functions:
```cpp ```cpp
using json = nlohmann::json; using nlohmann::json;
namespace ns { namespace ns {
void to_json(json& j, const person& p) { void to_json(json& j, const person& p) {
@@ -1257,7 +1257,7 @@ See the page [quality assurance](https://json.nlohmann.me/community/quality_assu
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
// for convenience // for convenience
using json = nlohmann::json; using nlohmann::json;
``` ```
to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang). to the files you want to process JSON and set the necessary switches to enable C++11 (e.g., `-std=c++11` for GCC and Clang).
+2 -1
View File
@@ -341,13 +341,14 @@ def download(url, docs) -> str:
raise ValueError(f'not an http(s) URL: {url}') raise ValueError(f'not an http(s) URL: {url}')
req = urllib.request.Request(u.geturl(), headers={'User-Agent': USER_AGENT}) req = urllib.request.Request(u.geturl(), headers={'User-Agent': USER_AGENT})
# (the scheme is checked above) # (the scheme is checked above)
# nosemgrep: python.lang.security.audit.dynamic-urllib-use-detected.dynamic-urllib-use-detected
with urllib.request.urlopen(req, timeout=20) as r: # nosec B310 with urllib.request.urlopen(req, timeout=20) as r: # nosec B310
data = r.read() data = r.read()
ctype = r.headers.get_content_type() ctype = r.headers.get_content_type()
path = urllib.parse.unquote(u.path).lstrip('/') path = urllib.parse.unquote(u.path).lstrip('/')
ext = os.path.splitext(path)[1] ext = os.path.splitext(path)[1]
if u.query or not ext or path.endswith('/'): if u.query or not ext or path.endswith('/'):
digest = hashlib.sha1(url.encode(), usedforsecurity=False).hexdigest()[:12] digest = hashlib.sha256(url.encode()).hexdigest()[:12]
path = os.path.join(os.path.dirname(path), digest + CONTENT_TYPE_EXT.get(ctype, ext or '.bin')) path = os.path.join(os.path.dirname(path), digest + CONTENT_TYPE_EXT.get(ctype, ext or '.bin'))
rel = os.path.normpath(os.path.join('assets', 'external', u.hostname, path)) rel = os.path.normpath(os.path.join('assets', 'external', u.hostname, path))
out = os.path.join(docs, rel) out = os.path.join(docs, rel)
@@ -67,7 +67,9 @@ class (either explicitly or via the conversion operators).
## See also ## See also
- [to_json](to_json.md) - [`to_json`](to_json.md) - convert a C++ value to JSON
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - write your own `from_json` and `to_json` functions
- [Converting values](../../features/conversions.md) - overview of `get`, `get_to` and implicit conversions
## Version history ## Version history
@@ -30,6 +30,14 @@ struct adl_serializer {
- [**from_json**](from_json.md) - convert a JSON value to any value type - [**from_json**](from_json.md) - convert a JSON value to any value type
- [**to_json**](to_json.md) - convert any value type to a JSON value - [**to_json**](to_json.md) - convert any value type to a JSON value
## See also
- [Arbitrary type conversions](../../features/arbitrary_types.md) - how to make your types convertible
- [`get`](../basic_json/get.md) - / [`get_to`](../basic_json/get_to.md) - convert a JSON value to a C++ type
- [`basic_json`](../basic_json/basic_json.md) - construct a JSON value from a C++ value
- [`NLOHMANN_DEFINE_TYPE_INTRUSIVE`](../macros/nlohmann_define_type_intrusive.md) - generate the conversion functions for a type
- [Specializing enum conversion](../../features/enum_conversion.md) - serializing enums as JSON strings
## Version history ## Version history
- Added in version 2.1.0. - Added in version 2.1.0.
@@ -36,7 +36,9 @@ This function is usually called by the constructors of the [basic_json](../basic
## See also ## See also
- [from_json](from_json.md) - [`from_json`](from_json.md) - convert JSON to a C++ value
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - write your own `from_json` and `to_json` functions
- [Converting values](../../features/conversions.md) - overview of `get`, `get_to` and implicit conversions
## Version history ## Version history
+33 -4
View File
@@ -23,6 +23,9 @@ Checks whether the input is valid JSON.
respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to respectively as UTF-8, UTF-16, and UTF-32. If `SentinelType` differs from `IteratorType`, it must be comparable to
the iterator type with `operator!=`. the iterator type with `operator!=`.
Ill-formed UTF-16 and UTF-32 sequences are rejected: a lone surrogate, a high surrogate that is not followed by its
low surrogate, and a code point above `U+10FFFF` all make this function return `false`.
Unlike the [`parse()`](parse.md) function, this function neither throws an exception in case of invalid JSON input Unlike the [`parse()`](parse.md) function, this function neither throws an exception in case of invalid JSON input
(i.e., a parse error) nor creates diagnostic information. (i.e., a parse error) nor creates diagnostic information.
@@ -35,9 +38,12 @@ Unlike the [`parse()`](parse.md) function, this function neither throws an excep
- a `#!c FILE` pointer (throws if null) - a `#!c FILE` pointer (throws if null)
- a C-style array of characters - a C-style array of characters
- a pointer to a null-terminated string of single byte characters (throws if null) - a pointer to a null-terminated string of single byte characters (throws if null)
- a `std::string` - a `std::string` or a `std::string_view` (C++17)
- a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators - a container `obj` for which `begin(obj)` and `end(obj)` produce a valid pair of iterators
(as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`) (as found via ADL or member functions, with semantics compatible to `std::begin` and `std::end`)
- wide characters (`wchar_t`, `char16_t`, `char32_t`), which are converted to UTF-8: a wide string object
(`std::wstring`, `std::u16string`, `std::u32string`) or an array (e.g. a wide string literal); a pointer to a
null-terminated wide string (e.g. `std::u16string::c_str()`) is not supported
`IteratorType` `IteratorType`
: a compatible iterator type, for instance. : a compatible iterator type, for instance.
@@ -125,17 +131,37 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
--8<-- "examples/accept__iterator_pair.output" --8<-- "examples/accept__iterator_pair.output"
``` ```
??? example "Example: (3) reading from UTF-16 strings"
The encoding is deduced from the character type of the input. String literals like `u"..."`, `U"..."`, and
`L"..."` work as well.
```cpp
--8<-- "examples/accept__wide_string.cpp"
```
Output:
```json
--8<-- "examples/accept__wide_string.output"
```
## See also ## See also
- [parse](parse.md) - deserialize from a compatible input - [`parse`](parse.md) - deserialize from a compatible input
- [sax_parse](sax_parse.md) - parse input using the SAX interface - [`sax_parse`](sax_parse.md) - parse input using the SAX interface
- [operator>>](../operator_gtgt.md) - deserialize from stream - [`operator>>`](../operator_gtgt.md) - deserialize from stream
- [`JSON_STRICT_NUL_HANDLING`](../macros/json_strict_nul_handling.md) - opt in to rejecting a NUL byte in the input - [`JSON_STRICT_NUL_HANDLING`](../macros/json_strict_nul_handling.md) - opt in to rejecting a NUL byte in the input
instead of treating it as end of input instead of treating it as end of input
- [`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md) - read a `std::istream` one character - [`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md) - read a `std::istream` one character
at a time at a time
- [`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md) - read a `FILE*` with the locking stdio - [`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md) - read a `FILE*` with the locking stdio
functions functions
- [Parsing](../../features/parsing/index.md) - overview of the parsing functions
- [Comments](../../features/comments.md) - ignore `//` and `/* */` comments while parsing
- [Trailing Commas](../../features/trailing_commas.md) - accept trailing commas in arrays and objects
- [Parsing and Exceptions](../../features/parsing/parse_exceptions.md) - handling parse errors and locating them in the input
- [Parsing Untrusted Input](../../features/parsing/untrusted_input.md) - limits and checks for input you do not control
## Version history ## Version history
@@ -151,6 +177,9 @@ outside of a string, invalid) byte; see the [FAQ entry](../../home/faq.md#nul-by
([`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md)). ([`JSON_DISABLE_STREAM_BULK_SCAN`](../macros/json_disable_stream_bulk_scan.md)).
- Parsing from a `FILE*` locks the file once instead of once per character in version 3.13.0 - Parsing from a `FILE*` locks the file once instead of once per character in version 3.13.0
([`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md)). ([`JSON_DISABLE_UNLOCKED_FILE_IO`](../macros/json_disable_unlocked_file_io.md)).
- 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; before that, some such sequences were accepted or
ended the input silently.
!!! warning "Deprecation" !!! warning "Deprecation"
+6 -4
View File
@@ -69,10 +69,12 @@ Arrays are stored as pointers in a `basic_json` type. That is, for any access to
## See also ## See also
- [object_t](object_t.md) the type used to store JSON objects - [`object_t`](object_t.md) - the type used to store JSON objects
- [binary_t](binary_t.md) the type used to store binary values - [`binary_t`](binary_t.md) - the type used to store binary values
- [is_array](is_array.md) checks whether the JSON value is an array - [`is_array`](is_array.md) - checks whether the JSON value is an array
- [max_size](max_size.md) returns the maximum possible number of elements - [`max_size`](max_size.md) - returns the maximum possible number of elements
- [Types](../../features/types/index.md) - how arrays are stored
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the `ArrayType` template parameter
## Version history ## Version history
@@ -46,7 +46,8 @@ The function is equivalent to `static_cast<json_base_class_t&>(j)` (or `static_c
## See also ## See also
- [json_base_class_t](json_base_class_t.md) - type of the custom base class - [`json_base_class_t`](json_base_class_t.md) - type of the custom base class
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the `CustomBaseClass` template parameter
## Version history ## Version history
+8 -7
View File
@@ -230,18 +230,19 @@ Strong exception safety: if an exception occurs, the original value stays intact
## See also ## See also
- documentation on [checked access](../../features/element_access/checked_access.md) - [Checked access](../../features/element_access/checked_access.md) - element access with range checking
- [`operator[]`](operator%5B%5D.md) for unchecked access by reference - [`operator[]`](operator%5B%5D.md) - unchecked access by reference
- [`value`](value.md) for access with default value - [`value`](value.md) - access with default value
- [basic_json_view::at](../basic_json_view/at.md) - the same access on a zero-copy view - [`basic_json_view::at`](../basic_json_view/at.md) - the same access on a zero-copy view
- [Element Access](../../features/element_access/index.md) - overview of all ways to access elements
- [JSON Pointer](../../features/json_pointer.md) - access nested values with a pointer
## Version history ## Version history
1. Added in version 1.0.0. 1. Added in version 1.0.0.
2. Added in version 1.0.0. 2. Added in version 1.0.0.
3. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as 3. Added in version 3.11.0. Support for keys convertible to `std::string_view` added in version 3.13.0, consistently
already supported by [`operator[]`](operator[].md), [`value`](value.md), [`find`](find.md), and other lookup across the lookup functions.
functions.
4. Added in version 2.0.0. Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) instead of 4. Added in version 2.0.0. Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) instead of
[`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) for a one-character array index that is not [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) for a one-character array index that is not
a digit (e.g., `/x`) in version 3.13.0, as it already did for longer ones. a digit (e.g., `/x`) in version 3.13.0, as it already did for longer ones.
+4 -3
View File
@@ -57,10 +57,11 @@ Constant.
## See also ## See also
- [front](front.md) to access the first element - [`front`](front.md) - to access the first element
- [basic_json_view::back](../basic_json_view/back.md) - the same access on a zero-copy view - [`basic_json_view::back`](../basic_json_view/back.md) - the same access on a zero-copy view
- [Element Access](../../features/element_access/index.md) - overview of all ways to access elements
## Version history ## Version history
- Added in version 1.0.0. - Added in version 1.0.0.
- Adjusted code to return reference to binary values in version 3.8.0. - Binary values are supported since version 3.8.0.
+22 -18
View File
@@ -113,19 +113,22 @@ basic_json(basic_json&& other) noexcept;
```mermaid ```mermaid
flowchart TD flowchart TD
A(["initializer_list init"]) --> B{"empty, or every element is a 2-element<br/>array whose first element is a string?"} A(["initializer_list init"]) --> B{{"empty, or every element is a 2-element<br/>array whose first element is a string?"}}
B -->|"yes"| C{"type_deduction"} B -->|"yes"| C{{"type_deduction"}}
B -->|"no"| D{"type_deduction"} B -->|"no"| D{{"type_deduction"}}
C -->|"true"| OBJ["create object"] C -->|"true"| OBJ["create object"]
C -->|"false"| E{"manual_type"} C -->|"false"| E{{"manual_type"}}
E -->|"object"| OBJ E -->|"object"| OBJ
E -->|"array"| ARR["create array"] E -->|"array"| ARR["create array"]
D -->|"true"| ARR D -->|"true"| ARR
D -->|"false"| F{"manual_type"} D -->|"false"| F{{"manual_type"}}
F -->|"array"| ARR F -->|"array"| ARR
F -->|"object"| ERR["throw type_error.301"] F -->|"object"| ERR["throw type_error.301"]
``` ```
<p class="nj-caption" markdown>Decision flow for an initializer list: hexagons are checks, edge labels are their
outcomes, and rectangles are the resulting value or exception.</p>
The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows: The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows:
1. The empty initializer list is written as `#!cpp {}` which is exactly an empty JSON object. 1. The empty initializer list is written as `#!cpp {}` which is exactly an empty JSON object.
@@ -473,24 +476,25 @@ basic_json(basic_json&& other) noexcept;
## See also ## See also
- [array](array.md) create a JSON array value, forcing array creation from an initializer list even when it looks like - [`array`](array.md) - create a JSON array value, forcing array creation from an initializer list even when it looks like
an object an object
- [object](object.md) create a JSON object value, forcing object creation from an initializer list - [`object`](object.md) - create a JSON object value, forcing object creation from an initializer list
- [binary](binary.md) create a JSON binary array value - [`binary`](binary.md) - create a JSON binary array value
- [operator=](operator=.md) copy assignment operator - [`operator=`](operator=.md) - copy assignment operator
- [Creating JSON values](../../features/creating_values.md) - the article on creating JSON values - [Creating JSON values](../../features/creating_values.md) - the article on creating JSON values
- [Converting values](../../features/conversions.md) - which C++ types can be converted
## Version history ## Version history
1. Since version 1.0.0. 1. Added in version 1.0.0.
2. Since version 1.0.0. 2. Added in version 1.0.0.
3. Since version 2.1.0. 3. Added in version 2.1.0.
4. Since version 3.2.0. Explicit for different string types if `JSON_USE_IMPLICIT_CONVERSIONS` is `0` since 4. Added in version 3.1.2. Explicit for different string types if `JSON_USE_IMPLICIT_CONVERSIONS` is `0` since
version 3.13.0. version 3.13.0.
5. Since version 1.0.0. 5. Added in version 1.0.0.
6. Since version 1.0.0. 6. Added in version 1.0.0.
7. Since version 1.0.0. Fixed in version 3.13.0 to also check the iterator range for binary values; before, a range 7. Added in version 1.0.0. Fixed in version 3.13.0 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, 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. unlike the other primitive types.
8. Since version 1.0.0. 8. Added in version 1.0.0.
9. Since version 1.0.0. 9. Added in version 1.0.0.
+11 -6
View File
@@ -7,7 +7,12 @@ const_iterator begin() const noexcept;
Returns an iterator to the first element. Returns an iterator to the first element.
![Illustration from cppreference.com](../../images/range-begin-end.svg) <div class="nj-fig-wrap" markdown>
--8<-- "images/range-begin-end.svg"
</div>
<p class="nj-caption" markdown>`begin()` points to the first element and `end()` to the position after the last element;
the dashed cell is the past-the-last position, which must not be dereferenced.</p>
## Return value ## Return value
@@ -39,12 +44,12 @@ Constant.
## See also ## See also
- [end](end.md) returns an iterator to one past the last element - [`end`](end.md) - returns an iterator to one past the last element
- [cbegin](cbegin.md) returns a const iterator to the first element - [`cbegin`](cbegin.md) - returns a const iterator to the first element
- [rbegin](rbegin.md) returns a reverse iterator to the last element - [`rbegin`](rbegin.md) - returns a reverse iterator to the last element
- [items](items.md) returns an iteration proxy to access keys and values during range-based for loops - [`items`](items.md) - returns an iteration proxy to access keys and values during range-based for loops
- [Iterators](../../features/iterators.md) - the article on iterators - [Iterators](../../features/iterators.md) - the article on iterators
- [basic_json_view::begin](../basic_json_view/begin.md) - the same iteration on a zero-copy view (in document order, - [`basic_json_view::begin`](../basic_json_view/begin.md) - the same iteration on a zero-copy view (in document order,
not sorted by key) not sorted by key)
## Version history ## Version history
+5 -4
View File
@@ -63,10 +63,11 @@ initialization of a binary array type, for backwards compatibility and so it doe
## See also ## See also
- [binary_t](binary_t.md) type for binary values - [Binary formats](../../features/binary_formats/index.md) - formats that can store binary values
- [get_binary](get_binary.md) get a reference to the stored binary value - [`binary_t`](binary_t.md) - type for binary values
- [is_binary](is_binary.md) return whether the value is binary - [`get_binary`](get_binary.md) - get a reference to the stored binary value
- [byte_container_with_subtype](../byte_container_with_subtype/index.md) container for binary values with subtype - [`is_binary`](is_binary.md) - return whether the value is binary
- [`byte_container_with_subtype`](../byte_container_with_subtype/index.md) - container for binary values with subtype
- [Binary Values](../../features/binary_values.md) - the article on binary values - [Binary Values](../../features/binary_values.md) - the article on binary values
## Version history ## Version history
+3 -1
View File
@@ -117,7 +117,9 @@ type `#!cpp binary_t*` must be dereferenced.
## See also ## See also
- [byte_container_with_subtype](../byte_container_with_subtype/index.md) - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [Binary formats](../../features/binary_formats/index.md) - formats that can store binary values
- [`byte_container_with_subtype`](../byte_container_with_subtype/index.md) - container type used by binary values
## Version history ## Version history
+3 -1
View File
@@ -47,7 +47,9 @@ Boolean values are stored directly inside a `basic_json` type.
## See also ## See also
- [is_boolean](is_boolean.md) checks whether the JSON value is a boolean - [`is_boolean`](is_boolean.md) - checks whether the JSON value is a boolean
- [Types](../../features/types/index.md) - how booleans are stored
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the `BooleanType` template parameter
## Version history ## Version history
+10 -5
View File
@@ -6,7 +6,12 @@ const_iterator cbegin() const noexcept;
Returns an iterator to the first element. Returns an iterator to the first element.
![Illustration from cppreference.com](../../images/range-begin-end.svg) <div class="nj-fig-wrap" markdown>
--8<-- "images/range-begin-end.svg"
</div>
<p class="nj-caption" markdown>`cbegin()` points to the first element, like `begin()`, and `end()` to the position after
the last element; the dashed cell is the past-the-last position, which must not be dereferenced.</p>
## Return value ## Return value
@@ -38,11 +43,11 @@ Constant.
## See also ## See also
- [begin](begin.md) returns an iterator to the first element - [`begin`](begin.md) - returns an iterator to the first element
- [cend](cend.md) returns a const iterator to one past the last element - [`cend`](cend.md) - returns a const iterator to one past the last element
- [crbegin](crbegin.md) returns a const reverse iterator to the last element - [`crbegin`](crbegin.md) - returns a const reverse iterator to the last element
- [Iterators](../../features/iterators.md) - the article on iterators - [Iterators](../../features/iterators.md) - the article on iterators
- [basic_json_view::cbegin](../basic_json_view/cbegin.md) - the same iteration on a zero-copy view - [`basic_json_view::cbegin`](../basic_json_view/cbegin.md) - the same iteration on a zero-copy view
## Version history ## Version history
@@ -40,9 +40,10 @@ store
## See also ## See also
- [from_cbor](from_cbor.md) deserializes a JSON value from CBOR - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [input_format_t](input_format_t.md) the enumeration of supported input formats - [`from_cbor`](from_cbor.md) - deserializes a JSON value from CBOR
- [CBOR](../../features/binary_formats/cbor.md) - the article on the CBOR format - [`input_format_t`](input_format_t.md) - the enumeration of supported input formats
- [`CBOR`](../../features/binary_formats/cbor.md) - the article on the CBOR format
## Version history ## Version history
+10 -5
View File
@@ -6,7 +6,12 @@ const_iterator cend() const noexcept;
Returns an iterator to one past the last element. Returns an iterator to one past the last element.
![Illustration from cppreference.com](../../images/range-begin-end.svg) <div class="nj-fig-wrap" markdown>
--8<-- "images/range-begin-end.svg"
</div>
<p class="nj-caption" markdown>`cend()` points to the position after the last element, like `end()`, and `begin()` to
the first element; the dashed cell is the past-the-last position, which must not be dereferenced.</p>
## Return value ## Return value
@@ -38,11 +43,11 @@ Constant.
## See also ## See also
- [end](end.md) returns an iterator to one past the last element - [`end`](end.md) - returns an iterator to one past the last element
- [cbegin](cbegin.md) returns a const iterator to the first element - [`cbegin`](cbegin.md) - returns a const iterator to the first element
- [crend](crend.md) returns a const reverse iterator to one before the first element - [`crend`](crend.md) - returns a const reverse iterator to one before the first element
- [Iterators](../../features/iterators.md) - the article on iterators - [Iterators](../../features/iterators.md) - the article on iterators
- [basic_json_view::cend](../basic_json_view/cend.md) - the same iteration on a zero-copy view - [`basic_json_view::cend`](../basic_json_view/cend.md) - the same iteration on a zero-copy view
## Version history ## Version history
+3 -2
View File
@@ -54,8 +54,9 @@ All iterators, pointers, and references related to this container are invalidate
## See also ## See also
- [erase](erase.md) removes elements from a JSON value - [`erase`](erase.md) - removes elements from a JSON value
- [empty](empty.md) checks whether the JSON value has no elements - [`empty`](empty.md) - checks whether the JSON value has no elements
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history ## Version history
+6 -6
View File
@@ -134,16 +134,16 @@ Logarithmic in the size of the JSON object.
## See also ## See also
- [find](find.md) find a value in an object - [`find`](find.md) - find a value in an object
- [count](count.md) returns the number of occurrences of a key - [`count`](count.md) - returns the number of occurrences of a key
- [basic_json_view::contains](../basic_json_view/contains.md) - the same check on a zero-copy view - [`basic_json_view::contains`](../basic_json_view/contains.md) - the same check on a zero-copy view
- [Element Access](../../features/element_access/index.md#does-this-key-exist) - how to test whether a key exists
## Version history ## Version history
1. Added in version 3.11.0. 1. Added in version 3.11.0.
2. Added in version 3.6.0. Extended template `KeyType` to support comparable types in version 3.11.0. Fixed in 2. Added in version 3.6.0. Extended template `KeyType` to support comparable types in version 3.11.0. Support for keys
version 3.13.0 to consistently accept `std::string_view`-convertible keys, as already supported by convertible to `std::string_view` added in version 3.13.0, consistently across the lookup functions.
[`operator[]`](operator[].md), [`at`](at.md), [`value`](value.md), and other lookup functions.
3. Added in version 3.7.0. 3. Added in version 3.7.0.
4. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of 4. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of
causing undefined behavior at runtime. causing undefined behavior at runtime.
+6 -6
View File
@@ -85,15 +85,15 @@ Logarithmic in the size of the JSON object.
## See also ## See also
- [find](find.md) find a value in an object - [`find`](find.md) - find a value in an object
- [contains](contains.md) checks whether a key exists - [`contains`](contains.md) - checks whether a key exists
- [basic_json_view::count](../basic_json_view/count.md) - the same check on a zero-copy view - [`basic_json_view::count`](../basic_json_view/count.md) - the same check on a zero-copy view
- [Element Access](../../features/element_access/index.md#does-this-key-exist) - how to test whether a key exists
## Version history ## Version history
1. Added in version 3.11.0. 1. Added in version 3.11.0.
2. Added in version 1.0.0. Changed parameter `key` type to `KeyType&&` in version 3.11.0. Fixed in version 3.13.0 to 2. Added in version 1.0.0. Changed to support comparable key types in version 3.11.0. Support for keys convertible to
consistently accept `std::string_view`-convertible keys, as already supported by [`operator[]`](operator[].md), `std::string_view` added in version 3.13.0, consistently across the lookup functions.
[`at`](at.md), [`value`](value.md), and other lookup functions.
3. Deleted overload for integral key types added in version 3.13.0 to reject such calls at compile time instead of 3. Deleted overload for integral key types added in version 3.13.0 to reject such calls at compile time instead of
causing undefined behavior at runtime. causing undefined behavior at runtime.
+10 -4
View File
@@ -6,7 +6,13 @@ const_reverse_iterator crbegin() const noexcept;
Returns an iterator to the reverse-beginning; that is, the last element. Returns an iterator to the reverse-beginning; that is, the last element.
![Illustration from cppreference.com](../../images/range-rbegin-rend.svg) <div class="nj-fig-wrap" markdown>
--8<-- "images/range-rbegin-rend.svg"
</div>
<p class="nj-caption" markdown>`crbegin()` points to the last element, like `rbegin()`, and `rend()` to the position
before the first element. The upper row is the reversed sequence and the lower row the forward sequence; dashed arrows
link each reverse iterator to the forward iterator it stores, and dashed cells are past-the-last positions.</p>
## Return value ## Return value
@@ -38,9 +44,9 @@ Constant.
## See also ## See also
- [crend](crend.md) returns a const reverse iterator to one before the first element - [`crend`](crend.md) - returns a const reverse iterator to one before the first element
- [rbegin](rbegin.md) returns a reverse iterator to the last element - [`rbegin`](rbegin.md) - returns a reverse iterator to the last element
- [cbegin](cbegin.md) returns a const iterator to the first element - [`cbegin`](cbegin.md) - returns a const iterator to the first element
- [Iterators](../../features/iterators.md) - the article on iterators - [Iterators](../../features/iterators.md) - the article on iterators
## Version history ## Version history
+10 -4
View File
@@ -7,7 +7,13 @@ const_reverse_iterator crend() const noexcept;
Returns an iterator to the reverse-end; that is, one before the first element. This element acts as a placeholder, Returns an iterator to the reverse-end; that is, one before the first element. This element acts as a placeholder,
attempting to access it results in undefined behavior. attempting to access it results in undefined behavior.
![Illustration from cppreference.com](../../images/range-rbegin-rend.svg) <div class="nj-fig-wrap" markdown>
--8<-- "images/range-rbegin-rend.svg"
</div>
<p class="nj-caption" markdown>`crend()` points to the position before the first element, like `rend()`, and `rbegin()`
to the last element. The upper row is the reversed sequence and the lower row the forward sequence; dashed arrows link
each reverse iterator to the forward iterator it stores, and dashed cells are past-the-last positions.</p>
## Return value ## Return value
@@ -39,9 +45,9 @@ Constant.
## See also ## See also
- [crbegin](crbegin.md) returns a const reverse iterator to the last element - [`crbegin`](crbegin.md) - returns a const reverse iterator to the last element
- [rend](rend.md) returns a reverse iterator to one before the first element - [`rend`](rend.md) - returns a reverse iterator to one before the first element
- [cend](cend.md) returns a const iterator to one past the last element - [`cend`](cend.md) - returns a const iterator to one past the last element
- [Iterators](../../features/iterators.md) - the article on iterators - [Iterators](../../features/iterators.md) - the article on iterators
## Version history ## Version history
@@ -32,8 +32,10 @@ The actual comparator used depends on [`object_t`](object_t.md) and can be obtai
## See also ## See also
- [object_comparator_t](object_comparator_t.md) the comparator actually used by `object_t` - [`object_comparator_t`](object_comparator_t.md) - the comparator actually used by `object_t`
- [object_t](object_t.md) the type used to store JSON objects - [`object_t`](object_t.md) - the type used to store JSON objects
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the `ObjectType` template parameter
- [Object order](../../features/object_order.md) - preserve the insertion order of keys
## Version history ## Version history
+6 -5
View File
@@ -55,11 +55,12 @@ Currently, only `remove`, `add`, and `replace` operations are generated.
## See also ## See also
- [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902) - [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902) - specification of JSON Patch
- [patch](patch.md) applies a JSON Patch - [`patch`](patch.md) - applies a JSON Patch
- [patch_inplace](patch_inplace.md) applies a JSON Patch in place - [`patch_inplace`](patch_inplace.md) - applies a JSON Patch in place
- [merge_patch](merge_patch.md) applies a JSON Merge Patch - [`merge_patch`](merge_patch.md) - applies a JSON Merge Patch
- [merge_diff](merge_diff.md) creates a diff as a JSON Merge Patch - [`merge_diff`](merge_diff.md) - creates a diff as a JSON Merge Patch
- [JSON Patch and Diff](../../features/json_patch.md) - the article on JSON Patch
## Version history ## Version history
+3 -3
View File
@@ -89,9 +89,9 @@ Binary values are serialized as an object containing two keys:
## See also ## See also
- [to_string](to_string.md) returns a string representation of a JSON value - [`to_string`](to_string.md) - returns a string representation of a JSON value
- [operator<<](../operator_ltlt.md) serialize to stream - [`operator<<`](../operator_ltlt.md) - serialize to stream
- [`basic_json_view::dump`](../basic_json_view/dump.md) the corresponding function of `basic_json_view`, serializing - [`basic_json_view::dump`](../basic_json_view/dump.md) - the corresponding function of `basic_json_view`, serializing
directly from a flat index without building a `basic_json` value directly from a flat index without building a `basic_json` value
- [Serialization](../../features/serialization.md) - the serialization article - [Serialization](../../features/serialization.md) - the serialization article
+3 -3
View File
@@ -63,12 +63,12 @@ Logarithmic in the size of the container, O(log(`size()`)).
## See also ## See also
- [emplace_back](emplace_back.md) add a value to an array - [`emplace_back`](emplace_back.md) - add a value to an array
- [insert](insert.md) add values to an array/object - [`insert`](insert.md) - add values to an array/object
- [Modifying values](../../features/modifying_values.md) - the article on modifying values - [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history ## Version history
- Since version 2.0.8. - Added in version 2.0.8.
- Fixed in version 3.13.0: for [`ordered_json`](../ordered_json.md), the value could previously only be passed as an - Fixed in version 3.13.0: for [`ordered_json`](../ordered_json.md), the value could previously only be passed as an
rvalue; it can now also be passed as an lvalue or a `#!cpp const` lvalue, matching the behavior of `json`. rvalue; it can now also be passed as an lvalue or a `#!cpp const` lvalue, matching the behavior of `json`.
@@ -61,11 +61,11 @@ Amortized constant.
## See also ## See also
- [operator+=](operator+=.md) add a value to an array/object - [`operator+=`](operator+=.md) - add a value to an array/object
- [push_back](push_back.md) add a value to an array/object - [`push_back`](push_back.md) - add a value to an array/object
- [Modifying values](../../features/modifying_values.md) - the article on modifying values - [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history ## Version history
- Since version 2.0.8. - Added in version 2.0.8.
- Returns reference since 3.7.0. - Returns reference since 3.7.0.
+3 -3
View File
@@ -62,9 +62,9 @@ itself is empty which is `#!cpp false` in the case of a string.
## See also ## See also
- [size](size.md) returns the number of elements - [`size`](size.md) - returns the number of elements
- [clear](clear.md) clears the content and resets the value to the default value - [`clear`](clear.md) - clears the content and resets the value to the default value
- [basic_json_view::empty](../basic_json_view/empty.md) - the same check on a zero-copy view - [`basic_json_view::empty`](../basic_json_view/empty.md) - the same check on a zero-copy view
## Version history ## Version history
+10 -5
View File
@@ -7,7 +7,12 @@ const_iterator end() const noexcept;
Returns an iterator to one past the last element. Returns an iterator to one past the last element.
![Illustration from cppreference.com](../../images/range-begin-end.svg) <div class="nj-fig-wrap" markdown>
--8<-- "images/range-begin-end.svg"
</div>
<p class="nj-caption" markdown>`end()` points to the position after the last element and `begin()` to the first element;
the dashed cell is the past-the-last position, which must not be dereferenced.</p>
## Return value ## Return value
@@ -39,11 +44,11 @@ Constant.
## See also ## See also
- [begin](begin.md) returns an iterator to the first element - [`begin`](begin.md) - returns an iterator to the first element
- [cend](cend.md) returns a const iterator to one past the last element - [`cend`](cend.md) - returns a const iterator to one past the last element
- [rend](rend.md) returns a reverse iterator to one before the first element - [`rend`](rend.md) - returns a reverse iterator to one before the first element
- [Iterators](../../features/iterators.md) - the article on iterators - [Iterators](../../features/iterators.md) - the article on iterators
- [basic_json_view::end](../basic_json_view/end.md) - the same iteration on a zero-copy view - [`basic_json_view::end`](../basic_json_view/end.md) - the same iteration on a zero-copy view
## Version history ## Version history
+3 -2
View File
@@ -60,8 +60,9 @@ Constant.
## See also ## See also
- [start_pos](start_pos.md) to access the start position - [`start_pos`](start_pos.md) - to access the start position
- [JSON_DIAGNOSTIC_POSITIONS](../macros/json_diagnostic_positions.md) for an overview of the diagnostic positions - [`JSON_DIAGNOSTIC_POSITIONS`](../macros/json_diagnostic_positions.md) - overview of the supported conversions
- [Parsing and Exceptions](../../features/parsing/parse_exceptions.md) - handling parse errors and locating them in the input
## Version history ## Version history
+4 -5
View File
@@ -204,8 +204,8 @@ Strong exception safety: if an exception occurs, the original value stays intact
## See also ## See also
- [clear](clear.md) clears the contents - [`clear`](clear.md) - clears the contents
- [insert](insert.md) add values to an array/object - [`insert`](insert.md) - add values to an array/object
- [Modifying values](../../features/modifying_values.md) - the article on modifying values - [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history ## Version history
@@ -213,7 +213,6 @@ Strong exception safety: if an exception occurs, the original value stays intact
1. Added in version 1.0.0. Added support for binary types in version 3.8.0. 1. Added in version 1.0.0. Added support for binary types in version 3.8.0.
2. Added in version 1.0.0. Added support for binary types in version 3.8.0. 2. Added in version 1.0.0. Added support for binary types in version 3.8.0.
3. Added in version 1.0.0. 3. Added in version 1.0.0.
4. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as 4. Added in version 3.11.0. Support for keys convertible to `std::string_view` added in version 3.13.0, consistently
already supported by [`operator[]`](operator[].md), [`at`](at.md), [`value`](value.md), and other lookup across the lookup functions.
functions.
5. Added in version 1.0.0. 5. Added in version 1.0.0.
@@ -61,7 +61,7 @@ keep
## See also ## See also
- [dump](dump.md) serializes a JSON value, with an `error_handler_t` parameter to configure invalid UTF-8 handling - [`dump`](dump.md) - serializes a JSON value, with an `error_handler_t` parameter to configure invalid UTF-8 handling
- [Handling invalid UTF-8](../../features/serialization.md#handling-invalid-utf-8) - the article on handling invalid UTF-8 - [Handling invalid UTF-8](../../features/serialization.md#handling-invalid-utf-8) - the article on handling invalid UTF-8
## Version history ## Version history
+9 -2
View File
@@ -40,6 +40,9 @@ classDiagram
style json_exception fill:#CCCCFF style json_exception fill:#CCCCFF
``` ```
<p class="nj-caption" markdown>Class hierarchy of the library's exceptions; arrows point from a derived class to its
base class, and the highlighted box is `basic_json::exception`.</p>
Subclasses: Subclasses:
- [`parse_error`](parse_error.md) for exceptions indicating a parse error - [`parse_error`](parse_error.md) for exceptions indicating a parse error
@@ -80,8 +83,12 @@ constructor.
## See also ## See also
[List of exceptions](../../home/exceptions.md) - [List of exceptions](../../home/exceptions.md) - overview of all exceptions thrown by the library
- [Working Without Exceptions](../../features/no_exceptions.md) - using the library without exceptions
- [`JSON_DIAGNOSTICS`](../macros/json_diagnostics.md) - extended exception messages with the path of the failing value
- [Parsing and Exceptions](../../features/parsing/parse_exceptions.md) - parsing alternatives that do not throw
- [Debugging](../../home/debugging.md) - debugging aids
## Version history ## Version history
- Since version 3.0.0. - Added in version 3.0.0.
+6 -6
View File
@@ -91,16 +91,16 @@ Logarithmic in the size of the JSON object.
## See also ## See also
- [count](count.md) returns the number of occurrences of a key - [`count`](count.md) - returns the number of occurrences of a key
- [contains](contains.md) checks whether a key exists - [`contains`](contains.md) - checks whether a key exists
- [basic_json_view::find](../basic_json_view/find.md) - the same lookup on a zero-copy view (a duplicate key resolves - [`basic_json_view::find`](../basic_json_view/find.md) - the same lookup on a zero-copy view (a duplicate key resolves
to the first member, whereas `parse()` keeps the last) to the first member, whereas `parse()` keeps the last)
- [Element Access](../../features/element_access/index.md#does-this-key-exist) - how to test whether a key exists
## Version history ## Version history
1. Added in version 3.11.0. 1. Added in version 3.11.0.
2. Added in version 1.0.0. Changed to support comparable types in version 3.11.0. Fixed in version 3.13.0 to 2. Added in version 1.0.0. Changed to support comparable types in version 3.11.0. Support for keys convertible to
consistently accept `std::string_view`-convertible keys, as already supported by [`operator[]`](operator[].md), `std::string_view` added in version 3.13.0, consistently across the lookup functions.
[`at`](at.md), [`value`](value.md), and other lookup functions.
3. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of 3. Deleted overloads for integral key types added in version 3.13.0 to reject such calls at compile time instead of
causing undefined behavior at runtime. causing undefined behavior at runtime.
+2 -1
View File
@@ -58,7 +58,8 @@ Empty objects and arrays are flattened to `#!json null` and will not be reconstr
## See also ## See also
- [unflatten](unflatten.md) the reverse function - [`unflatten`](unflatten.md) - the reverse function
- [JSON Pointer](../../features/json_pointer.md#flatten-unflatten) - the article on JSON Pointer and flattening
## Version history ## Version history
+2 -2
View File
@@ -86,8 +86,8 @@ std::string format_as(const BasicJsonType& j)
## See also ## See also
- [dump](dump.md) - [`dump`](dump.md) - serialize a JSON value to a string
- [std::formatter<basic_json>](std_formatter.md) - the `std::format` (C++20) equivalent - [`std::formatter<basic_json>`](std_formatter.md) - the `std::format` (C++20) equivalent
- [Serialization](../../features/serialization.md) - the serialization article - [Serialization](../../features/serialization.md) - the serialization article
## Version history ## Version history
+10 -6
View File
@@ -107,12 +107,16 @@ Linear in the size of the input.
## See also ## See also
- [to_bjdata](to_bjdata.md) create a BJData serialization of a JSON value - [BJData](../../features/binary_formats/bjdata.md) - the format, its byte layout and how values are mapped
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format - [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format - [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
- [from_bson](from_bson.md) create a JSON value from an input in BSON format - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format - [`to_bjdata`](to_bjdata.md) - create a BJData serialization of a JSON value
- [from_bon8](from_bon8.md) create a JSON value from an input in BON8 format - [`from_cbor`](from_cbor.md) - create a JSON value from an input in CBOR format
- [`from_msgpack`](from_msgpack.md) - create a JSON value from an input in MessagePack format
- [`from_bson`](from_bson.md) - create a JSON value from an input in BSON format
- [`from_ubjson`](from_ubjson.md) - create a JSON value from an input in UBJSON format
- [`from_bon8`](from_bon8.md) - create a JSON value from an input in BON8 format
## Version history ## Version history
+9 -6
View File
@@ -96,12 +96,15 @@ Linear in the size of the input.
## See also ## See also
- [to_bon8](to_bon8.md) create a BON8 serialization of a JSON value - [`BON8`](../../features/binary_formats/bon8.md) - the format, its byte layout and how values are mapped
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format - [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format - [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
- [from_bson](from_bson.md) create a JSON value from an input in BSON format - [`to_bon8`](to_bon8.md) - create a BON8 serialization of a JSON value
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format - [`from_cbor`](from_cbor.md) - create a JSON value from an input in CBOR format
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format - [`from_msgpack`](from_msgpack.md) - create a JSON value from an input in MessagePack format
- [`from_bson`](from_bson.md) - create a JSON value from an input in BSON format
- [`from_ubjson`](from_ubjson.md) - create a JSON value from an input in UBJSON format
- [`from_bjdata`](from_bjdata.md) - create a JSON value from an input in BJData format
## Version history ## Version history
+11 -7
View File
@@ -108,13 +108,17 @@ Linear in the size of the input.
## See also ## See also
- [BSON specification](http://bsonspec.org/spec.html) - [`BSON`](../../features/binary_formats/bson.md) - the format, its byte layout and how values are mapped
- [to_bson](to_bson.md) for the analogous serialization - [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
- [from_cbor](from_cbor.md) for the related CBOR format - [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
- [from_msgpack](from_msgpack.md) for the related MessagePack format - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [from_ubjson](from_ubjson.md) for the related UBJSON format - [BSON specification](http://bsonspec.org/spec.html) - specification of the BSON format
- [from_bjdata](from_bjdata.md) for the related BJData format - [`to_bson`](to_bson.md) - the analogous serialization
- [from_bon8](from_bon8.md) for the related BON8 format - [`from_cbor`](from_cbor.md) - the related CBOR format
- [`from_msgpack`](from_msgpack.md) - the related MessagePack format
- [`from_ubjson`](from_ubjson.md) - the related UBJSON format
- [`from_bjdata`](from_bjdata.md) - the related BJData format
- [`from_bon8`](from_bon8.md) - the related BON8 format
## Version history ## Version history
+10 -6
View File
@@ -114,12 +114,16 @@ Linear in the size of the input.
## See also ## See also
- [to_cbor](to_cbor.md) create a CBOR serialization of a JSON value - [`CBOR`](../../features/binary_formats/cbor.md) - the format, its byte layout and how values are mapped
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format - [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
- [from_bson](from_bson.md) create a JSON value from an input in BSON format - [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format - [`to_cbor`](to_cbor.md) - create a CBOR serialization of a JSON value
- [from_bon8](from_bon8.md) create a JSON value from an input in BON8 format - [`from_msgpack`](from_msgpack.md) - create a JSON value from an input in MessagePack format
- [`from_bson`](from_bson.md) - create a JSON value from an input in BSON format
- [`from_ubjson`](from_ubjson.md) - create a JSON value from an input in UBJSON format
- [`from_bjdata`](from_bjdata.md) - create a JSON value from an input in BJData format
- [`from_bon8`](from_bon8.md) - create a JSON value from an input in BON8 format
## Version history ## Version history
@@ -107,12 +107,16 @@ Linear in the size of the input.
## See also ## See also
- [to_msgpack](to_msgpack.md) create a MessagePack serialization of a JSON value - [MessagePack](../../features/binary_formats/messagepack.md) - the format, its byte layout and how values are mapped
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format - [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
- [from_bson](from_bson.md) create a JSON value from an input in BSON format - [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
- [from_ubjson](from_ubjson.md) create a JSON value from an input in UBJSON format - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format - [`to_msgpack`](to_msgpack.md) - create a MessagePack serialization of a JSON value
- [from_bon8](from_bon8.md) create a JSON value from an input in BON8 format - [`from_cbor`](from_cbor.md) - create a JSON value from an input in CBOR format
- [`from_bson`](from_bson.md) - create a JSON value from an input in BSON format
- [`from_ubjson`](from_ubjson.md) - create a JSON value from an input in UBJSON format
- [`from_bjdata`](from_bjdata.md) - create a JSON value from an input in BJData format
- [`from_bon8`](from_bon8.md) - create a JSON value from an input in BON8 format
## Version history ## Version history
+10 -6
View File
@@ -107,12 +107,16 @@ Linear in the size of the input.
## See also ## See also
- [to_ubjson](to_ubjson.md) create a UBJSON serialization of a JSON value - [`UBJSON`](../../features/binary_formats/ubjson.md) - the format, its byte layout and how values are mapped
- [from_cbor](from_cbor.md) create a JSON value from an input in CBOR format - [Binary formats](../../features/binary_formats/index.md) - overview and comparison of the supported binary formats
- [from_msgpack](from_msgpack.md) create a JSON value from an input in MessagePack format - [Parsing untrusted input](../../features/parsing/untrusted_input.md) - limits and safe handling of hostile data
- [from_bson](from_bson.md) create a JSON value from an input in BSON format - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [from_bjdata](from_bjdata.md) create a JSON value from an input in BJData format - [`to_ubjson`](to_ubjson.md) - create a UBJSON serialization of a JSON value
- [from_bon8](from_bon8.md) create a JSON value from an input in BON8 format - [`from_cbor`](from_cbor.md) - create a JSON value from an input in CBOR format
- [`from_msgpack`](from_msgpack.md) - create a JSON value from an input in MessagePack format
- [`from_bson`](from_bson.md) - create a JSON value from an input in BSON format
- [`from_bjdata`](from_bjdata.md) - create a JSON value from an input in BJData format
- [`from_bon8`](from_bon8.md) - create a JSON value from an input in BON8 format
## Version history ## Version history
+4 -3
View File
@@ -50,11 +50,12 @@ Constant.
## See also ## See also
- [back](back.md) to access the last element - [`back`](back.md) - to access the last element
- [basic_json_view::front](../basic_json_view/front.md) - the same access on a zero-copy view (document order, not - [`basic_json_view::front`](../basic_json_view/front.md) - the same access on a zero-copy view (document order, not
sorted; duplicate keys are visited) sorted; duplicate keys are visited)
- [Element Access](../../features/element_access/index.md) - overview of all ways to access elements
## Version history ## Version history
- Added in version 1.0.0. - Added in version 1.0.0.
- Adjusted code to return reference to binary values in version 3.8.0. - Binary values are supported since version 3.8.0.
+9 -8
View File
@@ -178,16 +178,17 @@ overload (3).
## See also ## See also
- [get_to](get_to.md) convert and write into a passed value - [`get_to`](get_to.md) - convert and write into a passed value
- [get_ptr](get_ptr.md) get a pointer to the stored value - [`get_ptr`](get_ptr.md) - get a pointer to the stored value
- [get_ref](get_ref.md) get a reference to the stored value - [`get_ref`](get_ref.md) - get a reference to the stored value
- [operator ValueType](operator_ValueType.md) get a value via implicit conversion - [`operator ValueType`](operator_ValueType.md) - get a value via implicit conversion
- [Converting values](../../features/conversions.md) - the type conversions article - [Converting values](../../features/conversions.md) - the type conversions article
- [basic_json_view::get](../basic_json_view/get.md) - the same conversion on a zero-copy view (many types are - [`basic_json_view::get`](../basic_json_view/get.md) - the same conversion on a zero-copy view (many types are
converted without ever building a `basic_json` value) converted without ever building a `basic_json` value)
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - make your own types usable with `get`
## Version history ## Version history
1. Since version 2.1.0. 1. Added in version 2.1.0.
2. Since version 2.1.0. Extended to work with other specializations of `basic_json` in version 3.2.0. 2. Added in version 2.1.0. Extended to work with other specializations of `basic_json` in version 3.1.2.
3. Since version 1.0.0. 3. Added in version 1.0.0.
@@ -36,7 +36,7 @@ Constant.
## See also ## See also
- [basic_json](index.md#template-parameters) the class template, with `AllocatorType` as one of its template parameters - [`basic_json`](index.md#template-parameters) - the class template, with `AllocatorType` as one of its template parameters
- [Template Parameter Requirements](../../features/types/template_parameters.md#allocatortype) - the requirements for `AllocatorType` - [Template Parameter Requirements](../../features/types/template_parameters.md#allocatortype) - the requirements for `AllocatorType`
## Version history ## Version history
@@ -42,8 +42,11 @@ Constant.
## See also ## See also
- [get](get.md) get a value (explicit conversion) - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [get_ref](get_ref.md) get a reference to the stored value - [`binary`](binary.md) - create a binary value
- [`is_binary`](is_binary.md) - check whether a value is binary
- [`get`](get.md) - get a value (explicit conversion)
- [`get_ref`](get_ref.md) - get a reference to the stored value
## Version history ## Version history
+3 -2
View File
@@ -45,7 +45,7 @@ Constant.
#include <iostream> #include <iostream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
using json = nlohmann::json; using nlohmann::json;
int main() int main()
{ {
@@ -86,7 +86,8 @@ Constant.
## See also ## See also
- [get_ref()](get_ref.md) get a reference value - [`get_ref()`](get_ref.md) - get a reference value
- [Converting values](../../features/conversions.md) - getting values out, with or without copying
## Version history ## Version history
+3 -2
View File
@@ -60,9 +60,10 @@ Constant.
## See also ## See also
- [get_ptr()](get_ptr.md) get a pointer value - [`get_ptr()`](get_ptr.md) - get a pointer value
- [basic_json_view::get_string](../basic_json_view/get_string.md) - the closest counterpart on a zero-copy view: a - [`basic_json_view::get_string`](../basic_json_view/get_string.md) - the closest counterpart on a zero-copy view: a
string without a copy, but as a view rather than a reference to a value that must already exist string without a copy, but as a view rather than a reference to a value that must already exist
- [Converting values](../../features/conversions.md) - getting values out, with or without copying
## Version history ## Version history
+6 -5
View File
@@ -68,13 +68,14 @@ Depends on the `json_serializer<ValueType>::from_json()` implementation.
## See also ## See also
- [get](get.md) get a value (explicit conversion) - [`get`](get.md) - get a value (explicit conversion)
- [get_ref](get_ref.md) get a reference to the stored value - [`get_ref`](get_ref.md) - get a reference to the stored value
- [get_ptr](get_ptr.md) get a pointer to the stored value - [`get_ptr`](get_ptr.md) - get a pointer to the stored value
- [Converting values](../../features/conversions.md) - the type conversions article - [Converting values](../../features/conversions.md) - the type conversions article
- [basic_json_view::get_to](../basic_json_view/get_to.md) - the same conversion on a zero-copy view - [`basic_json_view::get_to`](../basic_json_view/get_to.md) - the same conversion on a zero-copy view
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - make your own types usable with `get_to`
## Version history ## Version history
- Since version 3.3.0. - Added in version 3.3.0.
- Added a `static_assert` with a clear message for `const` arguments in version 3.13.0. - Added a `static_assert` with a clear message for `const` arguments in version 3.13.0.
+27 -3
View File
@@ -44,6 +44,22 @@ are collected in [Template Parameter Requirements](../../features/types/template
- [**json**](../json.md) - default specialization - [**json**](../json.md) - default specialization
- [**ordered_json**](../ordered_json.md) - a specialization that maintains the insertion order of object keys - [**ordered_json**](../ordered_json.md) - a specialization that maintains the insertion order of object keys
## Documents and views
Besides `basic_json`, the library offers a second way to hold a parsed JSON text: a
[`basic_json_document`](../basic_json_document/index.md), which owns or borrows the text and holds a flat index of the
values in it, and a [`basic_json_view`](../basic_json_view/index.md), a read-only handle to one value of such a document.
Both are defined in the header `<nlohmann/json_view.hpp>`; see
[Zero-copy JSON views](../../features/json_view.md) for the concept and the trade-offs.
- [**json_document**](../json_document.md) / [**ordered_json_document**](../ordered_json_document.md) - read-only
documents of the `basic_json` specialization they belong to
- [**json_editable_document**](../json_editable_document.md) /
[**ordered_json_editable_document**](../ordered_json_editable_document.md) - documents that can be modified in place
- [**json_view**](../json_view.md) / [**ordered_json_view**](../ordered_json_view.md) - views of a document
- [**json_editable_view**](../json_editable_view.md) /
[**ordered_json_editable_view**](../ordered_json_editable_view.md) - views of an editable document
## Iterator invalidation ## Iterator invalidation
All operations that add values to an **array** ([`push_back`](push_back.md) , [`operator+=`](operator+=.md), All operations that add values to an **array** ([`push_back`](push_back.md) , [`operator+=`](operator+=.md),
@@ -172,7 +188,7 @@ The class satisfies the following concept requirements:
Functions to inspect the type of a JSON value. Functions to inspect the type of a JSON value.
- [**type**](type.md) - return the type of the JSON value - [**type**](type.md) - return the type of the JSON value
- [**operator value_t**](operator_value_t.md) - return the type of the JSON value - [`operator value_t`](operator_value_t.md) - return the type of the JSON value
- [**type_name**](type_name.md) - return the type as string - [**type_name**](type_name.md) - return the type as string
- [**is_primitive**](is_primitive.md) - return whether the type is primitive - [**is_primitive**](is_primitive.md) - return whether the type is primitive
- [**is_structured**](is_structured.md) - return whether the type is structured - [**is_structured**](is_structured.md) - return whether the type is structured
@@ -201,7 +217,7 @@ Direct access to the stored value of a JSON value.
- [**get_to**](get_to.md) - get a value and write it to a destination - [**get_to**](get_to.md) - get a value and write it to a destination
- [**get_ptr**](get_ptr.md) - get a pointer value - [**get_ptr**](get_ptr.md) - get a pointer value
- [**get_ref**](get_ref.md) - get a reference value - [**get_ref**](get_ref.md) - get a reference value
- [**operator ValueType**](operator_ValueType.md) - get a value - [`operator ValueType`](operator_ValueType.md) - get a value
- [**get_binary**](get_binary.md) - get a binary value - [**get_binary**](get_binary.md) - get a binary value
- [**as_base_class**](as_base_class.md) - access the custom base class - [**as_base_class**](as_base_class.md) - access the custom base class
@@ -342,7 +358,15 @@ Access to the JSON value
## See also ## See also
- [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format](https://tools.ietf.org/html/rfc8259) - [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format](https://tools.ietf.org/html/rfc8259) -
specification of the JSON data interchange format
- [`basic_json_document`](../basic_json_document/index.md) - / [`basic_json_view`](../basic_json_view/index.md) - parse a JSON
text into a flat index and read it through a view
- [Zero-copy JSON views](../../features/json_view.md) - when to use a document and a view instead of a `basic_json`
- [Types](../../features/types/index.md) - how JSON values are stored and which types exist
- [Converting values](../../features/conversions.md) - get values out of a JSON value and put values in
- [Creating JSON values](../../features/creating_values.md) - all the ways to build a JSON value
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - convert your own types to and from JSON
## Version history ## Version history
@@ -53,8 +53,9 @@ bon8
## See also ## See also
- [sax_parse](sax_parse.md) generic SAX parse interface, taking an `input_format_t` to select the input format - [`sax_parse`](sax_parse.md) - generic SAX parse interface, taking an `input_format_t` to select the input format
- [cbor_tag_handler_t](cbor_tag_handler_t.md) configures how CBOR tags are treated while parsing - [`cbor_tag_handler_t`](cbor_tag_handler_t.md) - configures how CBOR tags are treated while parsing
- [Binary Formats](../../features/binary_formats/index.md) - CBOR, MessagePack, BSON, and other formats
## Version history ## Version history
+5 -4
View File
@@ -185,10 +185,11 @@ Strong exception safety: if an exception occurs, the original value stays intact
## See also ## See also
- [emplace](emplace.md) add a value to an object - [`emplace`](emplace.md) - add a value to an object
- [emplace_back](emplace_back.md) add a value to an array - [`emplace_back`](emplace_back.md) - add a value to an array
- [push_back](push_back.md) add a value to an array/object - [`push_back`](push_back.md) - add a value to an array/object
- [update](update.md) merges objects - [`update`](update.md) - merges objects
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history ## Version history
@@ -40,6 +40,9 @@ classDiagram
style json_invalid_iterator fill:#CCCCFF style json_invalid_iterator fill:#CCCCFF
``` ```
<p class="nj-caption" markdown>Class hierarchy of the library's exceptions; arrows point from a derived class to its
base class, and the highlighted box is `basic_json::invalid_iterator`.</p>
## Member functions ## Member functions
- **what** - returns explanatory string - **what** - returns explanatory string
@@ -66,13 +69,15 @@ classDiagram
## See also ## See also
- [`exception`](exception.md) for the base class of all exceptions thrown by the library - [`exception`](exception.md) - the base class of all exceptions thrown by the library
- [List of iterator errors](../../home/exceptions.md#iterator-errors) - [List of iterator errors](../../home/exceptions.md#iterator-errors) - overview of iterator errors (`invalid_iterator`)
- [`parse_error`](parse_error.md) for exceptions indicating a parse error - [`parse_error`](parse_error.md) - exceptions indicating a parse error
- [`type_error`](type_error.md) for exceptions indicating executing a member function with a wrong type - [`type_error`](type_error.md) - exceptions indicating executing a member function with a wrong type
- [`out_of_range`](out_of_range.md) for exceptions indicating access out of the defined range - [`out_of_range`](out_of_range.md) - exceptions indicating access out of the defined range
- [`other_error`](other_error.md) for exceptions indicating other library errors - [`other_error`](other_error.md) - exceptions indicating other library errors
- [Exceptions](../../home/exceptions.md) - all exceptions and their error codes
- [`JSON_DIAGNOSTICS`](../macros/json_diagnostics.md) - extended exception messages with the path of the failing value
## Version history ## Version history
- Since version 3.0.0. - Added in version 3.0.0.
+6 -5
View File
@@ -36,11 +36,12 @@ Constant.
## See also ## See also
- [is_object](is_object.md) checks whether the JSON value is an object - [`is_object`](is_object.md) - checks whether the JSON value is an object
- [is_structured](is_structured.md) checks whether the JSON value is structured (array or object) - [`is_structured`](is_structured.md) - checks whether the JSON value is structured (array or object)
- [type](type.md) returns the type of the JSON value - [`type`](type.md) - returns the type of the JSON value
- [array_t](array_t.md) the type used to store JSON arrays - [`array_t`](array_t.md) - the type used to store JSON arrays
- [basic_json_view::is_array](../basic_json_view/is_array.md) - the same check on a zero-copy view - [`basic_json_view::is_array`](../basic_json_view/is_array.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
+5 -4
View File
@@ -36,10 +36,11 @@ Constant.
## See also ## See also
- [is_primitive](is_primitive.md) checks whether the JSON value is primitive - [Binary values](../../features/binary_values.md) - how binary values and subtypes are handled
- [binary_t](binary_t.md) the type used to store binary values - [`is_primitive`](is_primitive.md) - checks whether the JSON value is primitive
- [get_binary](get_binary.md) returns a reference to the stored binary value - [`binary_t`](binary_t.md) - the type used to store binary values
- [basic_json_view::is_binary](../basic_json_view/is_binary.md) - the same check on a zero-copy view - [`get_binary`](get_binary.md) - returns a reference to the stored binary value
- [`basic_json_view::is_binary`](../basic_json_view/is_binary.md) - the same check on a zero-copy view
## Version history ## Version history
@@ -36,9 +36,10 @@ Constant.
## See also ## See also
- [boolean_t](boolean_t.md) the type used to store JSON booleans - [`boolean_t`](boolean_t.md) - the type used to store JSON booleans
- [is_primitive](is_primitive.md) checks whether the JSON value is primitive - [`is_primitive`](is_primitive.md) - checks whether the JSON value is primitive
- [basic_json_view::is_boolean](../basic_json_view/is_boolean.md) - the same check on a zero-copy view - [`basic_json_view::is_boolean`](../basic_json_view/is_boolean.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
@@ -87,8 +87,9 @@ with `allow_exceptions` set to `#!cpp false`: a parse error then yields a discar
## See also ## See also
- [basic_json_view::is_discarded](../basic_json_view/is_discarded.md) - the corresponding check on a zero-copy view, - [`basic_json_view::is_discarded`](../basic_json_view/is_discarded.md) - the corresponding check on a zero-copy view,
which is `#!cpp true` if the view refers to no value which is `#!cpp true` if the view refers to no value
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
+6 -5
View File
@@ -36,11 +36,12 @@ Constant.
## See also ## See also
- [is_array](is_array.md) checks whether the JSON value is an array - [`is_array`](is_array.md) - checks whether the JSON value is an array
- [is_object](is_object.md) checks whether the JSON value is an object - [`is_object`](is_object.md) - checks whether the JSON value is an object
- [type](type.md) returns the type of the JSON value - [`type`](type.md) - returns the type of the JSON value
- [value_t](value_t.md) the enumeration of JSON types - [`value_t`](value_t.md) - the enumeration of JSON types
- [basic_json_view::is_null](../basic_json_view/is_null.md) - the same check on a zero-copy view - [`basic_json_view::is_null`](../basic_json_view/is_null.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
+6 -4
View File
@@ -46,10 +46,12 @@ constexpr bool is_number() const noexcept
## See also ## See also
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number - [`is_number_integer()`](is_number_integer.md) - check if the value is an integer or unsigned integer number
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number - [`is_number_unsigned()`](is_number_unsigned.md) - check if the value is an unsigned integer number
- [is_number_float()](is_number_float.md) check if the value is a floating-point number - [`is_number_float()`](is_number_float.md) - check if the value is a floating-point number
- [basic_json_view::is_number](../basic_json_view/is_number.md) - the same check on a zero-copy view - [`basic_json_view::is_number`](../basic_json_view/is_number.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
- [Number Handling](../../features/types/number_handling.md) - how numbers are stored and converted
## Version history ## Version history
@@ -37,10 +37,12 @@ Constant.
## See also ## See also
- [is_number()](is_number.md) check if the value is a number - [`is_number()`](is_number.md) - check if the value is a number
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number - [`is_number_integer()`](is_number_integer.md) - check if the value is an integer or unsigned integer number
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number - [`is_number_unsigned()`](is_number_unsigned.md) - check if the value is an unsigned integer number
- [basic_json_view::is_number_float](../basic_json_view/is_number_float.md) - the same check on a zero-copy view - [`basic_json_view::is_number_float`](../basic_json_view/is_number_float.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
- [Number Handling](../../features/types/number_handling.md) - how numbers are stored and converted
## Version history ## Version history
@@ -37,10 +37,12 @@ Constant.
## See also ## See also
- [is_number()](is_number.md) check if the value is a number - [`is_number()`](is_number.md) - check if the value is a number
- [is_number_unsigned()](is_number_unsigned.md) check if the value is an unsigned integer number - [`is_number_unsigned()`](is_number_unsigned.md) - check if the value is an unsigned integer number
- [is_number_float()](is_number_float.md) check if the value is a floating-point number - [`is_number_float()`](is_number_float.md) - check if the value is a floating-point number
- [basic_json_view::is_number_integer](../basic_json_view/is_number_integer.md) - the same check on a zero-copy view - [`basic_json_view::is_number_integer`](../basic_json_view/is_number_integer.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
- [Number Handling](../../features/types/number_handling.md) - how numbers are stored and converted
## Version history ## Version history
@@ -40,10 +40,12 @@ Constant.
## See also ## See also
- [is_number()](is_number.md) check if the value is a number - [`is_number()`](is_number.md) - check if the value is a number
- [is_number_integer()](is_number_integer.md) check if the value is an integer or unsigned integer number - [`is_number_integer()`](is_number_integer.md) - check if the value is an integer or unsigned integer number
- [is_number_float()](is_number_float.md) check if the value is a floating-point number - [`is_number_float()`](is_number_float.md) - check if the value is a floating-point number
- [basic_json_view::is_number_unsigned](../basic_json_view/is_number_unsigned.md) - the same check on a zero-copy view - [`basic_json_view::is_number_unsigned`](../basic_json_view/is_number_unsigned.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
- [Number Handling](../../features/types/number_handling.md) - how numbers are stored and converted
## Version history ## Version history
+6 -5
View File
@@ -36,11 +36,12 @@ Constant.
## See also ## See also
- [is_array](is_array.md) checks whether the JSON value is an array - [`is_array`](is_array.md) - checks whether the JSON value is an array
- [is_structured](is_structured.md) checks whether the JSON value is structured (array or object) - [`is_structured`](is_structured.md) - checks whether the JSON value is structured (array or object)
- [type](type.md) returns the type of the JSON value - [`type`](type.md) - returns the type of the JSON value
- [object_t](object_t.md) the type used to store JSON objects - [`object_t`](object_t.md) - the type used to store JSON objects
- [basic_json_view::is_object](../basic_json_view/is_object.md) - the same check on a zero-copy view - [`basic_json_view::is_object`](../basic_json_view/is_object.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
@@ -56,13 +56,14 @@ This library extends primitive types to binary types, because binary types are r
## See also ## See also
- [is_structured()](is_structured.md) returns whether the JSON value is structured - [`is_structured()`](is_structured.md) - returns whether the JSON value is structured
- [is_null()](is_null.md) returns whether the JSON value is `null` - [`is_null()`](is_null.md) - returns whether the JSON value is `null`
- [is_string()](is_string.md) returns whether the JSON value is a string - [`is_string()`](is_string.md) - returns whether the JSON value is a string
- [is_boolean()](is_boolean.md) returns whether the JSON value is a boolean - [`is_boolean()`](is_boolean.md) - returns whether the JSON value is a boolean
- [is_number()](is_number.md) returns whether the JSON value is a number - [`is_number()`](is_number.md) - returns whether the JSON value is a number
- [is_binary()](is_binary.md) returns whether the JSON value is a binary array - [`is_binary()`](is_binary.md) - returns whether the JSON value is a binary array
- [basic_json_view::is_primitive](../basic_json_view/is_primitive.md) - the same check on a zero-copy view - [`basic_json_view::is_primitive`](../basic_json_view/is_primitive.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
+5 -4
View File
@@ -36,10 +36,11 @@ Constant.
## See also ## See also
- [is_primitive](is_primitive.md) checks whether the JSON value is primitive - [`is_primitive`](is_primitive.md) - checks whether the JSON value is primitive
- [type](type.md) returns the type of the JSON value - [`type`](type.md) - returns the type of the JSON value
- [string_t](string_t.md) the type used to store JSON strings - [`string_t`](string_t.md) - the type used to store JSON strings
- [basic_json_view::is_string](../basic_json_view/is_string.md) - the same check on a zero-copy view - [`basic_json_view::is_string`](../basic_json_view/is_string.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
@@ -54,10 +54,11 @@ Note that though strings are containers in C++, they are treated as primitive va
## See also ## See also
- [is_primitive()](is_primitive.md) returns whether JSON value is primitive - [`is_primitive()`](is_primitive.md) - returns whether JSON value is primitive
- [is_array()](is_array.md) returns whether the value is an array - [`is_array()`](is_array.md) - returns whether the value is an array
- [is_object()](is_object.md) returns whether the value is an object - [`is_object()`](is_object.md) - returns whether the value is an object
- [basic_json_view::is_structured](../basic_json_view/is_structured.md) - the same check on a zero-copy view - [`basic_json_view::is_structured`](../basic_json_view/is_structured.md) - the same check on a zero-copy view
- [Types](../../features/types/index.md) - the JSON value types and how they are stored
## Version history ## Version history
+6 -5
View File
@@ -97,15 +97,16 @@ When iterating over an array, `key()` will return the index of the element as st
## See also ## See also
- [begin](begin.md) returns an iterator to the first element - [`begin`](begin.md) - returns an iterator to the first element
- [end](end.md) returns an iterator to one past the last element - [`end`](end.md) - returns an iterator to one past the last element
- [basic_json_view::items](../basic_json_view/items.md) - the same range on a zero-copy view (`#!cpp const auto`, - [`basic_json_view::items`](../basic_json_view/items.md) - the same range on a zero-copy view (`#!cpp const auto`,
not `#!cpp const auto&`: items are produced on the fly; document order, not sorted; duplicate keys are visited) not `#!cpp const auto&`: items are produced on the fly; document order, not sorted; duplicate keys are visited)
- [Iterators](../../features/iterators.md#access-object-keys-during-iteration) - the article on iterating over keys and values
## Version history ## Version history
- Added `iterator_wrapper` in version 3.0.0. - Added in version 3.1.0 as the replacement of the static function `iterator_wrapper`, which was available since
- Added `items` and deprecated `iterator_wrapper` in version 3.1.0. version 1.0.0 and is deprecated since version 3.1.0.
- Added structured binding support in version 3.5.0. - Added structured binding support in version 3.5.0.
!!! warning "Deprecation" !!! warning "Deprecation"
@@ -57,7 +57,7 @@ same name. Hidden members remain accessible via [`as_base_class`](as_base_class.
## See also ## See also
- [as_base_class](as_base_class.md) - access the custom base class - [`as_base_class`](as_base_class.md) - access the custom base class
- [Template Parameter Requirements](../../features/types/template_parameters.md#custombaseclass) - the requirements for `CustomBaseClass` - [Template Parameter Requirements](../../features/types/template_parameters.md#custombaseclass) - the requirements for `CustomBaseClass`
## Version history ## Version history
@@ -44,11 +44,12 @@ deserializes. See [Template Parameter Requirements](../../features/types/templat
## See also ## See also
- [adl_serializer](../adl_serializer/index.md) the default `json_serializer` - [`adl_serializer`](../adl_serializer/index.md) - the default `json_serializer`
- [get](get.md) explicit type conversion using the `json_serializer`'s `from_json()` method - [`get`](get.md) - explicit type conversion using the `json_serializer`'s `from_json()` method
- [get_to](get_to.md) explicit type conversion into a variable using the `json_serializer`'s `from_json()` method - [`get_to`](get_to.md) - explicit type conversion into a variable using the `json_serializer`'s `from_json()` method
- [Arbitrary Type Conversions](../../features/arbitrary_types.md) - the article on converting between JSON values and arbitrary types - [Arbitrary Type Conversions](../../features/arbitrary_types.md) - the article on converting between JSON values and arbitrary types
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the `JSONSerializer` template parameter
## Version history ## Version history
- Since version 2.0.0. - Added in version 2.1.0.
+3 -3
View File
@@ -56,9 +56,9 @@ string elements the JSON value can store which is `1`.
## See also ## See also
- [size](size.md) returns the number of elements - [`size`](size.md) - returns the number of elements
- [array_t](array_t.md) the type used to store JSON arrays - [`array_t`](array_t.md) - the type used to store JSON arrays
- [object_t](object_t.md) the type used to store JSON objects - [`object_t`](object_t.md) - the type used to store JSON objects
## Version history ## Version history
@@ -70,9 +70,10 @@ object operation (looking up a key, or adding one to the patch): logarithmic for
## See also ## See also
- [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396) - [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396) - specification of JSON Merge Patch
- [merge_patch](merge_patch.md) applies a JSON Merge Patch - [`merge_patch`](merge_patch.md) - applies a JSON Merge Patch
- [diff](diff.md) creates a diff as a JSON Patch - [`diff`](diff.md) - creates a diff as a JSON Patch
- [JSON Merge Patch](../../features/merge_patch.md) - the article on JSON Merge Patch
## Version history ## Version history
@@ -65,12 +65,13 @@ returned by `#!cpp (*this)[key]`); it is read as it was when `merge_patch()` was
## See also ## See also
- [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396) - [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396) - specification of JSON Merge Patch
- [patch](patch.md) apply a JSON patch - [`patch`](patch.md) - apply a JSON patch
- [merge_diff](merge_diff.md) creates a diff as a JSON Merge Patch - [`merge_diff`](merge_diff.md) - creates a diff as a JSON Merge Patch
- [JSON Merge Patch](../../features/merge_patch.md) - the article on JSON Merge Patch
## Version history ## Version history
- Added in version 3.0.0. - Added in version 3.1.0.
- Fixed use of freed or relocated memory when `apply_patch` is `#!cpp *this` or refers to a value contained in - Fixed use of freed or relocated memory when `apply_patch` is `#!cpp *this` or refers to a value contained in
`#!cpp *this`, in version 3.13.0. `#!cpp *this`, in version 3.13.0.
+5 -2
View File
@@ -48,8 +48,11 @@ Constant.
## See also ## See also
- [**NLOHMANN_JSON_VERSION_MAJOR**/**NLOHMANN_JSON_VERSION_MINOR**/**NLOHMANN_JSON_VERSION_PATCH**](../macros/nlohmann_json_version_major.md) - [`NLOHMANN_JSON_VERSION_MAJOR`](../macros/nlohmann_json_version_major.md) /
\- library version information [`NLOHMANN_JSON_VERSION_MINOR`](../macros/nlohmann_json_version_major.md) /
[`NLOHMANN_JSON_VERSION_PATCH`](../macros/nlohmann_json_version_major.md) - library version information
- [Integration](../../integration/index.md) - integrate the library
- [Supported Macros](../../features/macros.md) - guide to all supported macros
## Version history ## Version history
@@ -84,10 +84,11 @@ Floating-point number values are stored directly inside a `basic_json` type.
## See also ## See also
- [number_integer_t](number_integer_t.md) the type used to store JSON integer numbers - [`number_integer_t`](number_integer_t.md) - the type used to store JSON integer numbers
- [number_unsigned_t](number_unsigned_t.md) the type used to store JSON unsigned integer numbers - [`number_unsigned_t`](number_unsigned_t.md) - the type used to store JSON unsigned integer numbers
- [is_number_float](is_number_float.md) checks whether the JSON value is a floating-point number - [`is_number_float`](is_number_float.md) - checks whether the JSON value is a floating-point number
- [Number Handling](../../features/types/number_handling.md) - the article on number handling - [Number Handling](../../features/types/number_handling.md) - the article on number handling
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the number template parameters
## Version history ## Version history
@@ -80,10 +80,11 @@ Integer number values are stored directly inside a `basic_json` type.
## See also ## See also
- [number_unsigned_t](number_unsigned_t.md) the type used to store JSON unsigned integer numbers - [`number_unsigned_t`](number_unsigned_t.md) - the type used to store JSON unsigned integer numbers
- [number_float_t](number_float_t.md) the type used to store JSON floating-point numbers - [`number_float_t`](number_float_t.md) - the type used to store JSON floating-point numbers
- [is_number_integer](is_number_integer.md) checks whether the JSON value is a signed integer number - [`is_number_integer`](is_number_integer.md) - checks whether the JSON value is a signed integer number
- [Number Handling](../../features/types/number_handling.md) - the article on number handling - [Number Handling](../../features/types/number_handling.md) - the article on number handling
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the number template parameters
## Version history ## Version history
@@ -82,10 +82,11 @@ Integer number values are stored directly inside a `basic_json` type.
## See also ## See also
- [number_integer_t](number_integer_t.md) the type used to store JSON integer numbers - [`number_integer_t`](number_integer_t.md) - the type used to store JSON integer numbers
- [number_float_t](number_float_t.md) the type used to store JSON floating-point numbers - [`number_float_t`](number_float_t.md) - the type used to store JSON floating-point numbers
- [is_number_unsigned](is_number_unsigned.md) checks whether the JSON value is an unsigned integer number - [`is_number_unsigned`](is_number_unsigned.md) - checks whether the JSON value is an unsigned integer number
- [Number Handling](../../features/types/number_handling.md) - the article on number handling - [Number Handling](../../features/types/number_handling.md) - the article on number handling
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the number template parameters
## Version history ## Version history
@@ -27,8 +27,10 @@ and [`default_object_comparator_t`](default_object_comparator_t.md) otherwise.
## See also ## See also
- [object_t](object_t.md) the type used to store JSON objects - [`object_t`](object_t.md) - the type used to store JSON objects
- [default_object_comparator_t](default_object_comparator_t.md) the fallback comparator used when `object_t` has no `key_compare` member type - [`default_object_comparator_t`](default_object_comparator_t.md) - the fallback comparator used when `object_t` has no `key_compare` member type
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the `ObjectType` template parameter
- [Object order](../../features/object_order.md) - preserve the insertion order of keys
## Version history ## Version history
+5 -3
View File
@@ -125,10 +125,12 @@ the object is silently converted as an array of key-value pairs, which is incorr
## See also ## See also
- [array_t](array_t.md) the type used to store JSON arrays - [`array_t`](array_t.md) - the type used to store JSON arrays
- [string_t](string_t.md) the type used to store JSON strings - [`string_t`](string_t.md) - the type used to store JSON strings
- [object_comparator_t](object_comparator_t.md) the comparator used to order object keys - [`object_comparator_t`](object_comparator_t.md) - the comparator used to order object keys
- [Object Order](../../features/object_order.md) - the article on object key ordering - [Object Order](../../features/object_order.md) - the article on object key ordering
- [Types](../../features/types/index.md) - how objects are stored
- [Template Parameter Requirements](../../features/types/template_parameters.md) - requirements on the `ObjectType` template parameter
## Version history ## Version history
@@ -123,11 +123,12 @@ interpreted as `object_t::value_type` or `std::initializer_list<basic_json>`, se
## See also ## See also
- [emplace_back](emplace_back.md) add a value to an array - [`emplace_back`](emplace_back.md) - add a value to an array
- [push_back](push_back.md) add a value to an array/object - [`push_back`](push_back.md) - add a value to an array/object
- [Modifying values](../../features/modifying_values.md) - the article on modifying values
## Version history ## Version history
1. Since version 1.0.0. 1. Added in version 1.0.0.
2. Since version 1.0.0. 2. Added in version 1.0.0.
3. Since version 2.0.0. 3. Added in version 2.0.0.
+3 -2
View File
@@ -45,8 +45,9 @@ Linear.
## See also ## See also
- [basic_json](basic_json.md) create a JSON value - [`basic_json`](basic_json.md) - create a JSON value
- [swap](swap.md) exchanges the contents of two JSON values - [`swap`](swap.md) - exchanges the contents of two JSON values
- [Creating JSON values](../../features/creating_values.md) - ways to create and assign JSON values
## Version history ## Version history
+11 -9
View File
@@ -271,23 +271,25 @@ Strong exception safety: if an exception occurs, the original value stays intact
## See also ## See also
- documentation on [unchecked access](../../features/element_access/unchecked_access.md) - [Unchecked access](../../features/element_access/unchecked_access.md) - element access without range checking
- documentation on [runtime assertions](../../features/assertions.md) - [Runtime assertions](../../features/assertions.md) - assertions guarding against undefined behavior
- see [`at`](at.md) for access by reference with range checking - [`at`](at.md) - access by reference with range checking
- see [`value`](value.md) for access with default value - [`value`](value.md) - access with default value
- [basic_json_view::operator[]](../basic_json_view/operator%5B%5D.md) - the same access on a zero-copy view (a duplicate - [`basic_json_view::operator[]`](../basic_json_view/operator%5B%5D.md) - the same access on a zero-copy view (a duplicate
key resolves to the first member, whereas `parse()` keeps the last; a missing key gives a discarded view instead of key resolves to the first member, whereas `parse()` keeps the last; a missing key gives a discarded view instead of
undefined behavior) undefined behavior)
- [Element Access](../../features/element_access/index.md) - overview of all ways to access elements
- [JSON Pointer](../../features/json_pointer.md) - access nested values with a pointer
## Version history ## Version history
1. Added in version 1.0.0. Fixed in version 3.13.0 to throw `#!cpp std::length_error` instead of emptying the array and 1. Added in version 1.0.0. Fixed in version 3.13.0 to throw `#!cpp std::length_error` instead of emptying the array and
accessing it out of bounds when `idx` equals the maximum value of `size_type`. A missing index in the const version accessing it out of bounds when `idx` equals the maximum value of `size_type`. A missing index in the const version
is guarded by a runtime assertion since version 3.13.0. is guarded by a runtime assertion since version 3.13.0.
2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. Removed overloads for `T* key` (replaced by 3) 2. Added in version 1.0.0. Added overloads for `T* key` in version 1.1.0. The `T* key` overloads forward to
in version 3.11.0. overload 3 since version 3.11.0.
3. Added in version 3.11.0. Fixed in version 3.13.0 to consistently accept `std::string_view`-convertible keys, as 3. Added in version 3.11.0. Support for keys convertible to `std::string_view` added in version 3.13.0, consistently
already supported by [`at`](at.md), [`value`](value.md), [`find`](find.md), and other lookup functions. across the lookup functions.
4. Added in version 2.0.0. A missing array index in the const version is guarded by a runtime assertion since 4. Added in version 2.0.0. A missing array index in the const version is guarded by a runtime assertion since
version 3.13.0. Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) instead of version 3.13.0. Throws [`parse_error.109`](../../home/exceptions.md#jsonexceptionparse_error109) instead of
[`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) for a one-character array index that is not [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) for a one-character array index that is not
@@ -84,11 +84,11 @@ Linear in the size of the JSON value.
## See also ## See also
- [get](get.md) get a value (explicit conversion) - [`get`](get.md) - get a value (explicit conversion)
- [Converting values](../../features/conversions.md) - the type conversions article - [Converting values](../../features/conversions.md) - the type conversions article
## Version history ## Version history
- Since version 1.0.0. - Added in version 1.0.0.
- Macros `JSON_EXPLICIT`/[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) added - Macros `JSON_EXPLICIT`/[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) added
in version 3.9.0. in version 3.9.0.
@@ -168,9 +168,9 @@ Linear.
## See also ## See also
- [operator!=](operator_ne.md) compare for inequality - [`operator!=`](operator_ne.md) - compare for inequality
- [operator<=>](operator_spaceship.md) comparison: 3-way (C++20) - [`operator<=>`](operator_spaceship.md) - comparison: 3-way (C++20)
- [basic_json_view::operator==](../basic_json_view/operator_eq.md) - the same comparison on a zero-copy view, without - [`basic_json_view::operator==`](../basic_json_view/operator_eq.md) - the same comparison on a zero-copy view, without
building a `basic_json` value for it building a `basic_json` value for it
## Version history ## Version history
@@ -93,7 +93,7 @@ Linear.
## See also ## See also
- [**operator<=>**](operator_spaceship.md) comparison: 3-way - [`operator<=>`](operator_spaceship.md) - comparison: 3-way
## Version history ## Version history
@@ -83,7 +83,7 @@ Linear.
## See also ## See also
- [**operator<=>**](operator_spaceship.md) comparison: 3-way - [`operator<=>`](operator_spaceship.md) - comparison: 3-way
## Version history ## Version history
@@ -94,7 +94,7 @@ Linear.
## See also ## See also
- [**operator<=>**](operator_spaceship.md) comparison: 3-way - [`operator<=>`](operator_spaceship.md) - comparison: 3-way
## Version history ## Version history
@@ -94,7 +94,7 @@ Linear.
## See also ## See also
- [**operator<=>**](operator_spaceship.md) comparison: 3-way - [`operator<=>`](operator_spaceship.md) - comparison: 3-way
## Version history ## Version history
@@ -93,9 +93,9 @@ Linear.
## See also ## See also
- [operator==](operator_eq.md) comparison: equal - [`operator==`](operator_eq.md) - comparison: equal
- [operator<=>](operator_spaceship.md) comparison: 3-way (C++20) - [`operator<=>`](operator_spaceship.md) - comparison: 3-way (C++20)
- [basic_json_view::operator!=](../basic_json_view/operator_ne.md) - the same comparison on a zero-copy view, without - [`basic_json_view::operator!=`](../basic_json_view/operator_ne.md) - the same comparison on a zero-copy view, without
building a `basic_json` value for it building a `basic_json` value for it
## Version history ## Version history
Loaded 100 of 905 files, more files were not shown because too many files have changed in this diff. Show more