Skip to content

feat(toml): fix JSON to TOML root scope and null handling#2689

Open
LovesAsuna wants to merge 1 commit intomikefarah:masterfrom
LovesAsuna:fix-json-to-toml-conversion
Open

feat(toml): fix JSON to TOML root scope and null handling#2689
LovesAsuna wants to merge 1 commit intomikefarah:masterfrom
LovesAsuna:fix-json-to-toml-conversion

Conversation

@LovesAsuna
Copy link
Copy Markdown

@LovesAsuna LovesAsuna commented Apr 29, 2026

fix #2618
Summary of the change:

- Updated TOML root encoding so root-level scalar fields and regular arrays are emitted before any TOML table headers.                                           
  - This keeps fields like sort = [1] at the TOML root level.                                                                                                    
  - Reason: in TOML, once [highlight] or [[_source.cookie]] is emitted, later key-value pairs belong to that table. TOML has no syntax to “return” to the root   
table.
- Preserved array-of-table behavior for object arrays.
  - _source.cookie still becomes:
  [[_source.cookie]]
  - Reason: arrays of JSON objects should continue mapping to TOML array-of-table syntax.
- Changed JSON null handling for TOML output.
  - Null-valued object fields like Unparsed: null are now skipped instead of emitted as:
  Unparsed = ""
  - Reason: TOML has no native null, and converting null to an empty string changes the meaning.
- Added regression coverage for the reported JSON shape.
  - The test checks that sort stays root-scoped, _source.cookie is encoded correctly, and Unparsed is omitted.

In short: the fix prevents root fields from leaking into the previous TOML table and avoids incorrectly converting JSON nulls into empty strings.

Ensure root-level TOML attributes are emitted before table sections so fields like sort remain root-scoped. Skip null-valued object fields during TOML encoding
    instead of converting them to empty strings.
@LovesAsuna LovesAsuna changed the title feat(toml): fix JSON to TOML root scope and null handling #2618 feat(toml): fix JSON to TOML root scope and null handling Apr 29, 2026
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.

toml format conversion error

1 participant