YAML5 is a way of writing YAML files that makes them look like JSON5. In other words: it's not a new format.
This repository provides a useful tooling for you:
yaml5 lint
checks whether the YAML file complies with the YAML5 rulesyaml5 fmt
reads a YAML file and pretty-prints it as a YAML5 file (not implemented yet)
There is only one rule: your YAML file needs to be a valid JSON5 document.
The only difference is the single line comment syntax: use #
instead of //
.
Let's take an example from the json5.org:
{
# comments
unquoted: 'and you can quote me on that',
singleQuotes: 'I can use "double quotes" here',
lineBreaks: "Look, Mom! \
No \\n's!",
hexadecimal: 0xdecaf,
leadingDecimalPoint: .8675309, andTrailing: 8675309.,
positiveSign: +1,
trailingComma: 'in objects', andIn: ['arrays',],
"backwardsCompatible": "with JSON",
}
The yaml5 lint
tool does catch some corner cases, for example, it does check that you've used a valid unquoted object key following the ES5.1
rules.
All YAML documents that use features that are not part of the JSON5 format will be reported as errors:
$ cat bad.yml
foo:
- .inf
- 10
$ yaml5 lint bad.yml
bad.yml:1:4: used a key-value outside of an object
bad.yml:2:3: use a flow array syntax instead
bad.yml:2:5: infinity value should not be used
- You were searching for a "JSON with comments and trailing commas", but the JSON5 is not so popular
- You have a lot of YAML files but would like to keep them strict and free of the indentation-sensitive features
# The easiest way to build it from sources:
go get -u -v github.com/quasilyte/yaml5/cmd/yaml5
# Build yaml5 binary from sources + embed the version info so the "yaml5 version"
# can give an appropriate output. Note that GOBIN folder is set to the
# current directory (the cloned yaml5 repository in this example); you can
# choose any other binary destination.
git clone https://github.com/quasilyte/yaml5.git
cd yaml5
GOBIN=$(pwd) make
TODO: make a binary release.