Skip to content

fix json.stringify for inline object literals with booleans and numbers#73

Merged
cs01 merged 2 commits intomainfrom
worktree-fix-json-stringify
Mar 1, 2026
Merged

fix json.stringify for inline object literals with booleans and numbers#73
cs01 merged 2 commits intomainfrom
worktree-fix-json-stringify

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 1, 2026

fix json.stringify for inline object literals

Summary

  • JSON.stringify({ ... }) with inline object literals previously fell through to unhandled codegen paths, producing incorrect output for boolean and numeric fields
  • Added stringifyObjectLiteral in src/codegen/stdlib/json.ts that walks the ObjectNode AST and builds a yyjson document directly, handling strings, numbers, booleans, and nested objects
  • Added csyyjson_obj_add_obj C bridge function to create and attach child objects to a parent during stringification, enabling recursive nested object support
  • Declared the new extern in src/codegen/runtime/runtime.ts

Files Changed

File Change
c_bridges/yyjson-bridge.c add csyyjson_obj_add_obj for nested object construction
src/codegen/runtime/runtime.ts declare @csyyjson_obj_add_obj extern
src/codegen/stdlib/json.ts add stringifyObjectLiteral + buildJsonProperties (recursive)
tests/fixtures/builtins/json-stringify-inline-object.ts test: mixed string/bool/number fields
tests/fixtures/builtins/json-stringify-inline-bool.ts test: boolean-only fields
tests/fixtures/builtins/json-stringify-deep-object.ts test: deeply nested objects
tests/fixtures/builtins/json-stringify-spaces.ts test: spaces=2 and spaces=4 pretty-printing

@cs01 cs01 merged commit 0969cf4 into main Mar 1, 2026
12 checks passed
@cs01 cs01 deleted the worktree-fix-json-stringify branch March 1, 2026 03:23
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