yq/pkg/yqlib/doc/usage/json5.md
Robin H. Johnson 76dc8dcae8
feat: 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>
2026-01-13 19:59:04 -08:00

857 B

JSON5

JSON5 support in yq lets you parse JSON5 files (comments, trailing commas, single quotes, unquoted keys, hex numbers, Infinity, NaN) and convert them to other formats like YAML, or output JSON5.

Note: when converting JSON5 to YAML (or other formats), comments may move slightly because formats like YAML don't always have a distinct representation for certain JSON5 comment placements (e.g. /* foo */ { ... } vs { /* foo */ ... }). When converting JSON5 back to JSON5, yq keeps comments as close as possible to their original location.

Parse json5: comments, trailing commas, single quotes

Given a sample.json5 file of:

{
  // comment
  unquoted: 'single quoted',
  trailing: [1, 2,],
}

then

yq -P -p=json5 '.' sample.json5

will output

# comment
unquoted: single quoted
trailing:
  - 1
  - 2