--json: self-closing tags have null content#166
Open
bukzor wants to merge 1 commit intosibprogrammer:masterfrom
Open
--json: self-closing tags have null content#166bukzor wants to merge 1 commit intosibprogrammer:masterfrom
bukzor wants to merge 1 commit intosibprogrammer:masterfrom
Conversation
Empty XML elements (self-closing tags, immediate-closing tags, and
whitespace-only elements) now output as null in JSON instead of empty
objects {}.
This makes the JSON formatter consistent with the XML formatter, which
already treats these elements as semantically empty by collapsing them
to self-closing tags.
Changes:
- nodeToJSONInternal() returns nil for empty elements
- Added TestSelfClosingTagsHaveNullContent test
- Added TestWhitespaceOnlyTagsAreSelfClosing test
Example:
<tag/> → {"tag": null} (was {"tag": {}})
<tag> </tag> → {"tag": null} (was {"tag": {}})
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #166 +/- ##
==========================================
+ Coverage 80.57% 80.63% +0.05%
==========================================
Files 5 5
Lines 690 692 +2
==========================================
+ Hits 556 558 +2
Misses 92 92
Partials 42 42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Empty XML elements now output as
nullin JSON instead of empty objects{}.This makes the JSON formatter consistent with the XML formatter's treatment of empty elements.
Problem
The XML formatter already treats empty elements as semantically null by collapsing them to self-closing tags:
But the JSON formatter was inconsistent, treating them as empty containers:
Solution
Self-closing tags (and equivalent forms) now have
nullcontent in JSON:This applies to:
<tag/><tag></tag><tag> </tag>Changes
nodeToJSONInternal()to returnnilfor empty elementsTestSelfClosingTagsHaveNullContent- establishes JSON behaviorTestWhitespaceOnlyTagsAreSelfClosing- establishes XML formatter behaviorBreaking Change
This is a breaking change for users who:
typeof(value) == "object"on potentially empty elementsHowever,
{}was semantically incorrect - it implied a container that could have had properties, when xq had already decided (via XML formatting) that these elements are truly empty.🤖 Generated with Claude Code