this post was submitted on 15 Aug 2023
43 points (100.0% liked)

Experienced Devs

3956 readers
1 users here now

A community for discussion amongst professional software developers.

Posts should be relevant to those well into their careers.

For those looking to break into the industry, are hustling for their first job, or have just started their career and are looking for advice, check out:

founded 1 year ago
MODERATORS
 

.yaml, .toml, etc?

you are viewing a single comment's thread
view the rest of the comments
[–] simonced@lemmy.one 15 points 1 year ago (4 children)

A lot of good answers but I would add one note:

  • use a format that supports comments, and JSON is not one of those...
[–] AeroLemming@lemm.ee 12 points 1 year ago (3 children)

Of course it does!

{
  comment: "This data is super important and it runs the system or something",
  data: ["Some", "stuff", "here"]
}
[–] noli@programming.dev 17 points 1 year ago

You disgust me

[–] simonced@lemmy.one 1 points 1 year ago (1 children)

This is actually pretty genius, why haven't ever thought of that?

[–] AeroLemming@lemm.ee 1 points 1 year ago (1 children)

It's so easy to use, and you can read the comments from in your program too!

^(in case you weren't just playing along, please never do comments this way)

[–] simonced@lemmy.one 1 points 1 year ago (1 children)

I liked the idea to be honest. I can just call the entry "description" instead and all is good ^^

[–] AeroLemming@lemm.ee 2 points 1 year ago

Ideally, you would use TOML for human-readable configuration and document your JSON API with external documentation instead of sending comments around a bunch. If you need to display the description to the end user though, that would be a valid use case.

[–] sfera@beehaw.org 1 points 1 year ago (1 children)

How do you comment multiple properties separately?

[–] AeroLemming@lemm.ee 2 points 1 year ago (1 children)

Please don't actually do this. Comment stuff in the code and documentation, not the JSON.

[–] sfera@beehaw.org 1 points 1 year ago

Don't worry, I wouldn't do things like this in JSON. Nevertheless, it can be very useful to have comments along with configuration values, for example to explain the actual values (not their purpose) and why they were chosen. That's information you can't add to the code which processes the values.

[–] ChairmanMeow@programming.dev 3 points 1 year ago

I believe the JSON deserializer .NET ships with has options to allow C#-style comments in JSON files.

[–] kersplort@programming.dev 2 points 1 year ago

JSON5 is a superset of JSON that supports comments.

[–] vrighter@discuss.tchncs.de 1 points 1 year ago

json with comments can be parsed by a yaml parser. It's how I write yaml, in fact (yaml is a superset of json. any valid json is valid yaml, but it also supports comments)