-
-
Notifications
You must be signed in to change notification settings - Fork 732
feat: JSON5 support #2569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: JSON5 support #2569
Conversation
Reference: https://spec.json5.org/ Co-authored-by: Codex <codex@openai.com> Generated-with: OpenAI Codex CLI (partial) Signed-off-by: Robin H. Johnson <rjohnson@coreweave.com>
|
new push has more test coverage for cases that I didn't think of in the initial write |
| } | ||
| intBytes, err := json.Marshal(value) | ||
| if err != nil { | ||
| return "null" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should log warning with error details here
| case "!!str": | ||
| stringBytes, err := json.Marshal(node.Value) | ||
| if err != nil { | ||
| return "null" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
| } | ||
|
|
||
| func writeJSON5CommentBlock(writer io.Writer, comment string, indentString string, depth int) error { | ||
| comment = strings.ReplaceAll(comment, "\r\n", "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently had to do a bunch of fixes in the yaml decoder (
Line 57 in 5428019
| if strings.HasSuffix(line, "\r\n") { |
| if err := writeString(writer, indent); err != nil { | ||
| return err | ||
| } | ||
| if err := writeString(writer, "// "+line+"\n"); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why you're not keeping the original comment delimiter?
| EOL | ||
|
|
||
| read -r -d '' expected << EOM | ||
| // hello |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to round trip the delimiter, this will definitely be raised as an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds JSON5 support to yq, enabling parsing and output of JSON5 format files. JSON5 extends JSON with features like comments, trailing commas, single quotes, unquoted keys, hex numbers, and special numeric values (Infinity, NaN).
Changes:
- Implements JSON5 decoder and encoder with full support for JSON5 syntax including comments, trailing commas, and special numeric values
- Adds build tags (
yq_nojson5) to allow excluding JSON5 support for minimal builds - Includes comprehensive test coverage for JSON5 parsing, encoding, and error cases
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/yqlib/decoder_json5.go | Implements JSON5 parser with support for comments, trailing commas, hex numbers, and special values |
| pkg/yqlib/encoder_json5.go | Implements JSON5 encoder that preserves comments and outputs valid JSON5 syntax |
| pkg/yqlib/json5_test.go | Comprehensive test scenarios for JSON5 decoding, encoding, and roundtrip operations |
| pkg/yqlib/encoder_json5_test.go | Unit tests for JSON5 encoder edge cases and comment handling |
| pkg/yqlib/no_json5.go | Stub implementations for builds with JSON5 disabled |
| pkg/yqlib/format.go | Registers JSON5 format with aliases "json5" and "j5" |
| pkg/yqlib/decoder_test.go | Adds support for flexible error message assertions in tests |
| scripts/build-tinygo-yq.sh | Adds yq_nojson5 build tag for minimal TinyGo builds |
| scripts/build-small-yq.sh | Adds yq_nojson5 build tag for minimal standard builds |
| cmd/utils_test.go | Tests for JSON5 format configuration and auto-detection |
| acceptance_tests/*.sh | Acceptance tests for JSON5 input/output scenarios |
| examples/*.json5 | Example JSON5 files demonstrating supported features |
| pkg/yqlib/doc/usage/*.md | Documentation for JSON5 support |
| project-words.txt | Adds "json5" to spelling dictionary |
| README.md | Updates help text to include JSON5 format options |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Currently, the `yq_nojson` feature must be enabled when using TinyGo. | ||
| tinygo build -no-debug -tags "yq_nolua yq_noini yq_notoml yq_noxml yq_nojson yq_nocsv yq_nobase64 yq_nouri yq_noprops yq_nosh yq_noshell yq_nohcl yq_nokyaml" . | ||
| tinygo build -no-debug -tags "yq_nolua yq_noini yq_notoml yq_noxml yq_nojson yq_nocsv yq_nobase64 yq_nouri yq_noprops yq_nosh yq_noshell yq_nohcl yq_nokyaml yq_nojson5" . |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build tag yq_nojson appears twice in the command. The second occurrence should be removed since yq_nojson5 is the new tag being added for JSON5 support.
Reference: https://spec.json5.org/
Co-authored-by: Codex codex@openai.com
Generated-with: OpenAI Codex CLI (partial)
Signed-off-by: Robin H. Johnson rjohnson@coreweave.com