|
| 1 | +# TAGLINE |
| 2 | + |
| 3 | +Convert between YAML, JSON, TOML, and HCL |
| 4 | + |
| 5 | +# TLDR |
| 6 | + |
| 7 | +Convert a **YAML file to JSON** |
| 8 | + |
| 9 | +```cat [file.yaml] | yj``` |
| 10 | + |
| 11 | +Convert a **YAML file to TOML** |
| 12 | + |
| 13 | +```cat [file.yaml] | yj -yt``` |
| 14 | + |
| 15 | +Convert a **JSON file to YAML** |
| 16 | + |
| 17 | +```cat [file.json] | yj -jy``` |
| 18 | + |
| 19 | +Convert a **TOML file to JSON** with **indented output** |
| 20 | + |
| 21 | +```cat [file.toml] | yj -ti``` |
| 22 | + |
| 23 | +Convert an **HCL file to JSON** |
| 24 | + |
| 25 | +```cat [file.hcl] | yj -c``` |
| 26 | + |
| 27 | +Convert a **JSON file to TOML** with **indented output** |
| 28 | + |
| 29 | +```cat [file.json] | yj -jti``` |
| 30 | + |
| 31 | +# SYNOPSIS |
| 32 | + |
| 33 | +**yj** [**-**][_ytjcrneikhv_] |
| 34 | + |
| 35 | +# PARAMETERS |
| 36 | + |
| 37 | +**-yj**, **-y** |
| 38 | +> Convert YAML to JSON (default) |
| 39 | +
|
| 40 | +**-yy** |
| 41 | +> Convert YAML to YAML |
| 42 | +
|
| 43 | +**-yt** |
| 44 | +> Convert YAML to TOML |
| 45 | +
|
| 46 | +**-yc** |
| 47 | +> Convert YAML to HCL |
| 48 | +
|
| 49 | +**-jy**, **-r** |
| 50 | +> Convert JSON to YAML |
| 51 | +
|
| 52 | +**-jj** |
| 53 | +> Convert JSON to JSON |
| 54 | +
|
| 55 | +**-jt** |
| 56 | +> Convert JSON to TOML |
| 57 | +
|
| 58 | +**-jc** |
| 59 | +> Convert JSON to HCL |
| 60 | +
|
| 61 | +**-tj**, **-t** |
| 62 | +> Convert TOML to JSON |
| 63 | +
|
| 64 | +**-ty** |
| 65 | +> Convert TOML to YAML |
| 66 | +
|
| 67 | +**-tt** |
| 68 | +> Convert TOML to TOML |
| 69 | +
|
| 70 | +**-tc** |
| 71 | +> Convert TOML to HCL |
| 72 | +
|
| 73 | +**-cj**, **-c** |
| 74 | +> Convert HCL to JSON |
| 75 | +
|
| 76 | +**-cy** |
| 77 | +> Convert HCL to YAML |
| 78 | +
|
| 79 | +**-ct** |
| 80 | +> Convert HCL to TOML |
| 81 | +
|
| 82 | +**-cc** |
| 83 | +> Convert HCL to HCL |
| 84 | +
|
| 85 | +**-n** |
| 86 | +> Do not convert inf, -inf, and NaN to/from strings (YAML or TOML only) |
| 87 | +
|
| 88 | +**-e** |
| 89 | +> Escape HTML characters in output (JSON only) |
| 90 | +
|
| 91 | +**-i** |
| 92 | +> Indent output (JSON or TOML only) |
| 93 | +
|
| 94 | +**-k** |
| 95 | +> Attempt to parse keys as objects or numeric types (YAML output only) |
| 96 | +
|
| 97 | +**-h** |
| 98 | +> Show help |
| 99 | +
|
| 100 | +**-v** |
| 101 | +> Show version |
| 102 | +
|
| 103 | +# DESCRIPTION |
| 104 | + |
| 105 | +**yj** is a lightweight command-line tool for converting between **YAML**, **JSON**, **TOML**, and **HCL** serialization formats. It reads from **stdin** and writes to **stdout**, making it easy to compose with other Unix tools via piping. |
| 106 | + |
| 107 | +A key feature of yj is that it **preserves map key order** during conversion, which many similar tools do not. The default behavior converts YAML to JSON. Conversion direction is specified by combining format letters: the first letter is the input format and the second is the output format (e.g. **-yt** for YAML to TOML). |
| 108 | + |
| 109 | +Supported format versions are YAML v1.2, TOML v1.0.0, JSON RFC 7159, and HCL v1. |
| 110 | + |
| 111 | +# CAVEATS |
| 112 | + |
| 113 | +Only **HCL v1** is supported. Modern Terraform files using HCL2 syntax may not parse correctly. The tool reads exclusively from stdin and writes to stdout; there are no flags for specifying input or output files directly. JSON and TOML output is compact by default and requires **-i** for human-readable indented output. |
| 114 | + |
| 115 | +# HISTORY |
| 116 | + |
| 117 | +**yj** was created by **Stephen Levine** and first released in **March 2017**. It is written in **Go** and is available on GitHub at sclevine/yj. The tool is installable via Homebrew and as pre-built binaries for Linux, macOS, and Windows. It is licensed under the Apache License 2.0. |
| 118 | + |
| 119 | +# SEE ALSO |
| 120 | + |
| 121 | +[jq](/man/jq)(1), [yq](/man/yq)(1), [toml](/man/toml)(1), [python](/man/python)(1) |
0 commit comments