Skip to content

Preserve null values in fractured JSON table formatting - #2915

Merged
lemire merged 1 commit into
simdjson:masterfrom
aikhanjum:codex/simdjson-correctness
Oct 9, 2026
Merged

lemire merged 1 commit into
simdjson:masterfrom
aikhanjum:codex/simdjson-correctness

Conversation

@aikhanjum

Copy link
Copy Markdown
Contributor

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

  • Bug fix

Reproduction

On upstream e9cdb8751db846a5b527b2999415cf4aa69ec366, save this program as repro.cpp, build the library, and run it with default formatting options.

#include "simdjson.h"
#include <iostream>

int main() {
  std::cout << simdjson::fractured_json_string(R"([[[1]],[null]])") << '\n';
}
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
./repro

The 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.

ctest --test-dir build --output-on-failure -LE explicitonly -j 4

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=ON and SIMDJSON_SANITIZE_UNDEFINED=ON each passed the complete fractured_json_tests target. 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

  • Added regression coverage that failed before the fix.
  • Built locally and passed the checks described above.
  • Kept the implementation and regression in one focused commit.
  • No public API or README changes are needed.
  • No matching existing issue was found.

@lemire
lemire force-pushed the codex/simdjson-correctness branch from 5cf2634 to 1d9b91f Compare October 8, 2026 04:22
@lemire
lemire merged commit 6e9e79a into simdjson:master Oct 9, 2026
100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants