Repository navigation
Conversation
nlohmann
added this pull request to stack #5636
September 29, 2026 14:20
Owner
Author
|
CI fixes for this PR (commits 87a041a and ab4f646):
Verified with the CI's own image — posted by Claude Code on behalf of @nlohmann |
This was referenced Sep 29, 2026
nlohmann
removed this pull request from stack #5636
September 30, 2026 13:19
nlohmann
force-pushed
the
json-view/08-view-builder
branch
from
September 30, 2026 13:20
ab4f646 to
dc9899f
Compare
nlohmann
added this pull request to stack #5739
September 30, 2026 13:21
nlohmann
force-pushed
the
json-view/08-view-builder
branch
3 times, most recently
from
September 30, 2026 18:06
7030188 to
c195988
Compare
nlohmann
marked this pull request as ready for review
September 30, 2026 18:18
nlohmann
force-pushed
the
json-view/08-view-builder
branch
from
September 30, 2026 18:19
c195988 to
e96e298
Compare
nlohmann
removed this pull request from stack #5739
October 6, 2026 09:26
nlohmann
force-pushed
the
json-view/08-view-builder
branch
from
October 6, 2026 09:28
2739c0b to
4303ba6
Compare
nlohmann
changed the base branch from
json-view/04-unicode-escapes
to
json-view/23-zmij
October 6, 2026 09:29
nlohmann
added this pull request to stack #5768
October 6, 2026 09:29
Add json_document and json_view, a read-only, zero-copy index of a JSON text, as the first public slice of the zero-copy view (#5295). A parse produces a flat array of 16-byte nodes in document order, one per value and one per object key. Strings stay in the source text; escaped strings are decoded into an arena. Integers are converted while their digits are in the cache; floats keep only their digit layout and are converted on read. Containers store the size of their subtree, so a reader can step over one in constant time. A document makes a handful of allocations, however many values it has. The parser accepts exactly what json::parse accepts, with every combination of ignore_comments and ignore_trailing_commas, with and without a trailing NUL, and under JSON_STRICT_NUL_HANDLING. It is portable C++11 and does not depend on byte order. basic_json_document adds parse, parse_copy, accept, read (reuses a document's memory), root, is_discarded, source, owns_source, node_count, memory_usage, and shrink_to_fit. basic_json_view adds type, the is_* queries, operator bool, size, empty, materialize, and source_offset. A parse error throws the same exception basic_json::parse would throw for the same input, message and position included. detail::abi_config keeps JSON_STRICT_NUL_HANDLING and JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON readable after json.hpp undefines them, in the ABI namespace so they always match the basic_json in use. A NUL byte that ends a // comment is the end of the input, as in parse() since #5696. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
nlohmann
force-pushed
the
json-view/08-view-builder
branch
from
October 7, 2026 14:44
4303ba6 to
759dd2e
Compare
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated and/or formatted correctly, or 📎 A ready-to-apply patch is attached to the failed workflow run as the git apply amalgamation.patchThis does not require installing astyle yourself. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the stack for the zero-copy view (#5295). This PR combines #5620 and #5621, which were reviewed separately before: the internal node index and parser, and the public
json_document/json_viewclasses built on it. Element access, values,dump(), and comparisons follow in later PRs, so each one stays reviewable.Summary
parse(): with comments enabled, a NUL byte that ends a//comment is the end of the input, as develop's lexer does since Keep a NUL byte ending a // comment as the end of input #5696; before, the view consumed it as part of the comment.json::parseaccepts: every combination ofignore_commentsandignore_trailing_commas, with and without a trailing NUL, and underJSON_STRICT_NUL_HANDLING. It is portable C++11, and nothing depends on the byte order: words are read in a fixed order, and literals are compared withmemcmp. The SIMD kernels come later in the stack.basic_json_document<BasicJsonType>:parse,parse_copy,accept,read(reuses the document's memory),root,is_discarded,source,owns_source,node_count,memory_usage,shrink_to_fit.basic_json_view<BasicJsonType>:type, theis_*queries,operator bool,size,empty,materialize,source_offset.json_document,json_view,ordered_json_document,ordered_json_view.std::string_view, C strings, character arrays, pointer ranges, and in C++20 other contiguous iterator ranges) or owned (an rvaluestd::string, moved in, and anything elseparse()accepts, copied or read).basic_json::parsewould throw for the same input. The library parser runs on the failing input (a cold path), so message, position, and id match. Inputs of 4 GiB or more are rejected with the newout_of_range.416.materialize(): builds the value with the SAX handlerparse()uses, soJSON_DIAGNOSTICSparent pointers are set as usual.detail::abi_configkeepsJSON_STRICT_NUL_HANDLINGandJSON_USE_LEGACY_DISCARDED_VALUE_COMPARISONreadable afterjson.hppundefines them at its end, in the ABI namespace, which already encodes both settings, so they always match thebasic_jsonin use.Performance
json_view
Measured on the regrouped stack
Measured on the regrouped stack (µs, best of 3 interleaved rounds of 15 runs; files from nativejson-benchmark). Apple M1 Max with Apple clang at
-O2; x86-64 on a KVM Haswell VPS, pinned to one core, GCC 13 / Clang 18 at-O2(the VPS is noisy, about ±5–10%).json_document::parsevsjson::parse(both at this PR):Earlier measurements (on the old stack)
json_document::parsevsjson::parse: 3.1-6.0x faster (twitter 0.24 vs 0.80 ms, canada 1.03 vs 6.16 ms). Parse plusmaterialize()is still 1.4-2.1x faster thanjson::parse.Apple M1, Google Benchmark, median of 5:
json::parsejson_document::parsejson::acceptjson_document::acceptmaterialize()of the whole document: 80.1, 4.65, 1.06, and 0.72 ms for the same four files.Core library (
json::parse/dump)Unaffected: this PR only adds internal code under
include/nlohmann/detail/view/and the new public headerjson_view.hpp.json.hpponly gains the internaldetail::abi_configconstants and the one include. No existing code path changes.Tests
unit-json_view_builder.cpp: 140,882 assertions comparing the node index withjson::parsefor handwritten, generated, and damaged documents under all option combinations; input fromstd::stringand from exact-size buffers with no read past the input under AddressSanitizer; deep nesting up to 100,000 levels; NUL, BOM, and whitespace cases; and the test-suite files.unit-json_view.cpp:materialize()equalsparse()for handwritten and generated documents, with duplicate keys, 100,000 levels of nesting, andJSON_DIAGNOSTICSparents; parse errors equalparse()'s, message included, for malformed inputs under all option combinations; every input kind, borrowed or owned; reuse withread(), moves,shrink_to_fit(), and source offsets.unit-json_view_macros.cpp: includes the header withoutJSON_TEST_KEEP_MACROS, as users do, and checks that the view relies on no macrojson.hppundefines and leaks none of its ownNLOHMANN_VIEW_*macros.fuzzer-parse_json_view.cpp): accept, value, and exception parity withjson::parse.Public API
New, additive API; nothing existing changes:
<nlohmann/json_view.hpp>withbasic_json_document,basic_json_view, and the aliasesjson_document,json_view,ordered_json_document,ordered_json_view.out_of_range.416(input of 4 GiB or more).json.hppgains the internaldetail::abi_configconstants (not part of the public API).aspect: json_viewis used bylabeler.ymland has to be created in the repository.Written by Claude Code.
🤖 Generated with Claude Code