mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 22:35:37 +00:00
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>
30 lines
857 B
Markdown
30 lines
857 B
Markdown
# 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:
|
|
```json5
|
|
{
|
|
// comment
|
|
unquoted: 'single quoted',
|
|
trailing: [1, 2,],
|
|
}
|
|
|
|
```
|
|
then
|
|
```bash
|
|
yq -P -p=json5 '.' sample.json5
|
|
```
|
|
will output
|
|
```yaml
|
|
# comment
|
|
unquoted: single quoted
|
|
trailing:
|
|
- 1
|
|
- 2
|
|
```
|
|
|