... I just don't even think about putting \\n at the end of a line and stuff. I never really had a gripe. I guess I've just been someone who is good at following instructions and I don't question this stuff.
No, it was named JSON5 as a subtle nod to HTML5, because it fixed a lot of stuff with the original format when using it for use cases like config files.
Because yaml is just a bolt on extension of JSON. It is json but it lets people omit most of the critical control structures in favor of inferring from whitespace characters.
TOML is indeed better for a lot of things, especially config. Not sure about other places yaml gets used, like in defining CI pipelines. I hate yaml there too however, it always takes me 3 times to get the right incantation for a variable interpolation.
I think something like Jenkins is better there, since its actual code, but Groovy also sucks.
(From what I'm reading it's MOST JSON is valid YAML, but there are differences: JSON allows tabs for indenting, and has some slight differences with escaping - like "\/" is valid JSON but invalid YAML. Surrogate pairs in JSON written like "\uD83D\uDE00" need to be written as "\U0001F600". Bottom line, be aware there are differences, but the main feature of YAML's JSON compatibility is that if the YAML indenting thing isn't very readable to you, you can just write stuff in a more JSON-like way, which, after decades of C and Java and Javascript programming, most of us are used to.)
I mean, it fully ignores white-space outside of strings so you could add whatever random tabs you want in your JSON file. But I wouldn't call it indenting if it has no meaning and is ignored by all valid JSON parsers...
JSON has optional indenting where the tab is just generic white space you can use without it impacting anything. You do not need to indent something in JSON, and it's only meaningful to human readers if you do.
However, tabs ARE meaningful in YAML, under certain circumstances they affect how the file is parsed.
Idk this looks like yaml with extra steps for the most part. You can write bastardized json with bare identifiers etc in yaml and it parses fine. Including iirc curries and squares to replace the white space and “-“ indentation notation if you want.
Edit: Then again if you are writing a config file for humans (ie why you want comments in it), JSON (with or without comments) maybe is not the right choice to start with /IMO
View all comments
173
u/pregister 8d ago
https://json5.org