Repository navigation
Preserve null values in fractured JSON table formatting - #2915
Merged
Merged
Conversation
lemire
force-pushed
the
codex/simdjson-correctness
branch
from
October 8, 2026 04:22
5cf2634 to
1d9b91f
Compare
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.
Description
The fractured JSON formatter can drop null rows or cells when aligning them alongside objects or arrays. This can silently delete array elements or produce an object key with no value. Stop building structural columns when a null is present, allowing the existing ordinary value formatter to preserve every value.
The fallback removes alignment for the whole rejected structural level. A null inside a container column disables alignment of that column's inner fields across rows. A whole null row among object or array rows disables table layout and aligned compact layout for the entire containing array, which may instead use unaligned compact lines. Scalar arrays containing null keep their existing alignment.
No existing issue is linked. Searches of current issues, open and merged PRs, and the discussions on #2879 and #2908 found no report or fix for this null loss.
Type of change
Reproduction
On upstream
e9cdb8751db846a5b527b2999415cf4aa69ec366, save this program asrepro.cpp, build the library, and run it with default formatting options.cmake -S . -B build -DSIMDJSON_DEVELOPER_MODE=ON cmake --build build --parallel 4 c++ -std=c++17 -Iinclude repro.cpp build/libsimdjson.a -o repro ./reproThe unpatched output is valid JSON but loses the null element.
[ [ [1] ], [ ] ]Expected content is
[[[1]],[null]], which the patch preserves. The related input[{"a":{"x":1}},{"a":null}]previously produced a key with a missing value and invalid JSON.Validation
The new regression was added before the production edit and failed on unchanged upstream because the null object value was missing. It checks eight inputs under default, table, and compact settings, including null whole rows and null nested cells. Reparsing and comparing contents catches both invalid JSON and silent data loss.
The full local suite passed all 142 tests before and after the fix. The new regression failed before the fix and passed afterward. Separate Debug builds with
SIMDJSON_SANITIZE=ONandSIMDJSON_SANITIZE_UNDEFINED=ONeach passed the completefractured_json_teststarget. The whitespace check also passed.Performance and limitations
A local formatter benchmark used pre-parsed synthetic documents with 2000 rows, three warmups and 30 formats per case across seven alternating baseline and patched rounds. Ordinary container input measured median times of 1.250 milliseconds before and 1.223 milliseconds after, with overlapping ranges. No speedup is claimed. Nullable cases change layout and correct lost data, so their timings do not represent equivalent work.
Validation used Apple Clang 17 on ARM64 macOS. Linux, Windows, x86, C++26 reflection, full sanitizer suites, and upstream CI have not been run for this patch.
AI assistance
OpenAI Codex assisted substantially with investigation, implementation, regression tests, local validation, and this description. I independently reproduced the original failure, reviewed the control flow, and corrected the description of the alignment tradeoff. I am responsible for the submitted change.
Checklist