Skip to content

fix: boolean values serialize as empty objects in JSON output#79

Merged
boolangery merged 3 commits into
masterfrom
fix/issue-76
Jul 19, 2026
Merged

fix: boolean values serialize as empty objects in JSON output#79
boolangery merged 3 commits into
masterfrom
fix/issue-76

Conversation

@boolangery

Copy link
Copy Markdown
Owner

What Problem This Solves

Boolean values (true / false) in parsed Lua ASTs were serializing as empty objects {} in JSON output, making them indistinguishable from each other and from other node types. Additionally, Node.to_json() crashed when _tokens was not set, and the value filter incorrectly dropped falsy values like False and 0.

Why This Change Was Made

Three changes in astnodes.py:

  1. TrueExpr now sets self.value = True, FalseExpr sets self.value = False — so the boolean value is preserved as a node attribute
  2. Node.to_json() filter changed from and v to and v is not None and v != [] — preserves False, 0, and other falsy-but-meaningful values
  3. Node.to_json() now uses hasattr(self, "_tokens") guard instead of crashing

User Impact

Before:

{comments: [], wrapped: false}  // is this true or false? Impossible to tell.

After:

{True: {value: true, start_char: 10, stop_char: 13, ...}}
{False: {value: false, start_char: 26, stop_char: 30, ...}}

Evidence

  • All 147 tests pass
  • Updated test_to_pretty_json to match the corrected (and richer) output format

Fixes #76

…alization

- Add  to TrueExpr and  to FalseExpr
  so boolean values are preserved in JSON output
- Fix Node.to_json() filter: change  to
  to preserve falsy values like False and 0
- Fix Node.to_json() crash when _tokens is missing (use hasattr guard)
- Update test_to_pretty_json to match the corrected to_json() output format

Fixes #76
@boolangery

Copy link
Copy Markdown
Owner Author

Please add an integration test

Verify that TrueExpr and FalseExpr JSON output includes the value
field, and that round-trip parsing preserves boolean values.
@boolangery

Copy link
Copy Markdown
Owner Author

Done — added test_cont_int_15 in test_integration.py (d67daff):

  • Parses local a, b = true, false
  • Asserts JSON contains "value": true and "value": false
  • Asserts round-trip to_lua_source preserves boolean values

Full suite: 148/148 pass ✅

@boolangery
boolangery merged commit 05d8d38 into master Jul 19, 2026
3 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.

Booleans might not be parsing properly?

1 participant