3 ms·
Just for fun, I wondered if YAML '#' comments could exist within a multi-line formatted JSON file. I cannot say the below holds for all YAML libraries, but can
by AdieuToLogic 4y ago
Just for fun, I wondered if YAML '#' comments could exist within a multi-line formatted JSON file.
I cannot say the below holds for all YAML libraries, but can say the below works.
Assume there is a file named "foo.yaml" which has the following content:
{
# this is a comment
"hello" : "world",
array : [
# first number
1,
# second number
2
]
}
Running:
ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' < foo.yaml
Yields the below without error:
{
"hello": "world",
"array": [
1,
2
]
}
HTH
- verdverm 4y agoyou can reduce further this by running: cue export foo.yaml --out json If you have an existing JSON file, add // comments wherever and run: cue export cue: - --out json < file.json The `cue: -` tells cue how to interpret stdin and has many options