Skip to content

Conversation

@robbat2
Copy link
Contributor

@robbat2 robbat2 commented Jan 10, 2026

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

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>
@robbat2
Copy link
Contributor Author

robbat2 commented Jan 14, 2026

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"
Copy link
Owner

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"
Copy link
Owner

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")
Copy link
Owner

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 (

if strings.HasSuffix(line, "\r\n") {
) to support both line endings 😅 - would be good to have this also support both to avoid a similar bug being raised

if err := writeString(writer, indent); err != nil {
return err
}
if err := writeString(writer, "// "+line+"\n"); err != nil {
Copy link
Owner

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
Copy link
Owner

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

@mikefarah mikefarah requested a review from Copilot January 20, 2026 23:46
Copy link
Contributor

Copilot AI left a 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" .
Copy link

Copilot AI Jan 20, 2026

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.

Copilot uses AI. Check for mistakes.
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.

2 participants