Skip to content

Write JSON.LazyValue as its materialized value - #491

Merged
quinnj merged 2 commits into
masterfrom
jq/write-lazyvalue
Oct 4, 2026
Merged

quinnj merged 2 commits into
masterfrom
jq/write-lazyvalue

Conversation

@quinnj

@quinnj quinnj commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

JSON.json(JSON.lazy("{\"a\":1}")) throws on a lazy object key, while lazy numbers and null are written as strings. Write a lazy value as its parsed value at the root and inside another container. Materialize nested values before the omission checks so omit_null and omit_empty see the actual value.

Keep this normalization in the writer: adding a general lowering method would also materialize sources used by typed parsing. Output follows ordinary parsed-value writing, including whitespace, key normalization, duplicate-key handling, custom styles, pretty printing, and byte-vector output. No exports or dependencies are added.

Validation: the 44 permanent regressions pass, and full suites pass on Julia 1.10.12 and 1.13.1, including current trim compile tests. An independent 1180-assertion comparison passes on each version across scalars, objects, arrays, nested containers, seven option/style combinations, string/pretty/byte-vector output, typed parsing, and error propagation. Ten focused checks on unchanged master give 2 passing, 4 failing, and 4 errored results. Current master is integrated without conflicts or a force push; all twelve hosted checks pass, including the Parsers 2.8.8/3 matrix, docs, and both coverage checks. The stable upload was accepted for this exact JSON.jl head.

AI disclosure: This work was prepared with assistance from OpenAI Codex.

Co-authored by Codex

Original change generated with Claude Code.

@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.51%. Comparing base (3d34308) to head (233f86a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #491      +/-   ##
==========================================
+ Coverage   92.50%   92.51%   +0.01%     
==========================================
  Files           7        7              
  Lines        1894     1897       +3     
==========================================
+ Hits         1752     1755       +3     
  Misses        142      142              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

JSON.json on a LazyValue never worked: lazy objects threw
"Value returned from `StructUtils.lowerkey` must be a string or real
number: JSON.PtrString", and lazy scalars were written as JSON strings
(JSON.lazy("1") wrote "1" with quotes; null wrote "nothing").

The writer had no case for LazyValue. Lazy objects and arrays were
walked with the lazy applyeach, which passes raw PtrString keys and
unmaterialized values (what parsing wants), and lazy scalars fell
through to a _string fallback that quoted the parsed value.

Write a LazyValue as its default materialization x[], lowered with the
write style, so JSON.json(x) matches JSON.json(x[]) for every write
option. json! handles a root lazy value; WriteClosure handles nested
ones before its omit_null/omit_empty checks. This isn't a
StructUtils.lower method because StructUtils.make also calls lower on
the lazy source it parses from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Retain the writer fix with current error-context and byte-vector output APIs.

AI disclosure: This work was prepared with assistance from OpenAI Codex.

Co-authored by Codex
@quinnj
quinnj merged commit 7ea3efd into master Oct 4, 2026
12 checks passed
@quinnj
quinnj deleted the jq/write-lazyvalue branch October 4, 2026 01:55
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.

1 participant