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

Experienced Devs

3978 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?

all 50 comments
sorted by: hot top controversial new old
[–] pileghoff@programming.dev 21 points 1 year ago (1 children)

I usually use Json5. It's JSON, but with all the weird quirks fixed (comments added, you can use hex numbers, you can have trailing commas etc.)

[–] 10nica@hexbear.net 3 points 1 year ago (1 children)

Oh that's interesting. Wonder how many libraries out there support it...

load more comments (1 replies)
[–] simonced@lemmy.one 16 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...
[–] 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)

[–] AverageCakeSlice@sh.itjust.works 16 points 1 year ago (4 children)

JSON by a mile. I hate the YAML plague, it’s some of the most unintuitive syntax I’ve seen and yet it’s everywhere in DevOps/SysOps.

[–] sylveon@programming.dev 9 points 1 year ago (1 children)

The only thing that really annoys me about JSON is that it doesn't allow comments.

[–] Hexarei@programming.dev 9 points 1 year ago

JSON5, bay-beee

GitHub Actions and Azure DevOps had me hating on YAML pretty quickly

[–] Hexarei@programming.dev 4 points 1 year ago (2 children)

Yeah, any language in which whitespace count is semantically significant can go suck fat nards.

[–] derpgon@programming.dev 8 points 1 year ago (1 children)

I mean, a valid JSON is a valid YAML

[–] Hexarei@programming.dev 6 points 1 year ago

I hate that you're correct lmao

[–] bignavy@programming.dev 8 points 1 year ago (1 children)

Not sure whether fantastic troll or just no exposure to Python.

Either way....I'm here for it.

[–] Hexarei@programming.dev 8 points 1 year ago (1 children)

Neither, I've written plenty of Python and I know how useful it can be. However, as someone who is neurospicy, I find languages that have semantically l significant white space to be frustrating to read.

Sure, there are tools to help with it. Sure, they help. But they don't replace how much more useful curly braces are at defining scope.

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

You’re not wrong. Having to figure out which element is borked in a yaml file is not great. And the implementation using yaml is all over the place, so even though tools do exist, they’re mediocre at best.

But, to be fair, Python has always done the same to me. As a fellow Neuro-spicy (and with a background in Java and C# and JavaScript), although the tools are better to point you in the right direction, significant white space (or indentations) are significant white space (or indentations).🤷‍♂️

load more comments (1 replies)
[–] spartanatreyu@programming.dev 14 points 1 year ago

It depends what you need your configuration file to be:

Need a well defined easy to understand concrete configuration file?

  • Use .toml. It was made to be both human and computer friendly while taking special attention to avoid the pitfalls commonly found in other configuration files by explicitly stating expected types around commonly confused areas.

Need a simple to implement configuration file?

  • Use .json. It's famous for being so simple it's ~~creator~~ "discoverer" could define it on a business card.

Need an abstract configuration file for more complicated setups?

  • Use .ncl. Nickle allows you to define functions so that you can generate/compute the correct configuration by changing a few variables/flags.
[–] aport@programming.dev 13 points 1 year ago (1 children)

Give the windows registry a shot.

[–] rikudou@lemmings.world 12 points 1 year ago (2 children)

Yaml for me, I really like it. And the fact that every valid JSON is also a valid YAML is nice.

[–] magnus@lemmy.ahall.se 3 points 1 year ago

YAML here as well.

Configuration many levels deep gets so much harder for me to read and write in JSON with all [], {} and ""

Also the lack of comments... And YAML still is more used in software I'm using than JSON5, so I'd rather skip yet another format/library to keep track of.

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

Please do not use YAML. It's a syntactic minefield. It also doesn't allow tab indentation, which is supremely irritating.

[–] rikudou@lemmings.world 3 points 1 year ago

As I said, I like it the most, so I will use it. I like its syntax (except for yes and no for booleans, but nothing's perfect). I don't care much for tabs vs spaces, I use tab in my IDE and whatever it does, it does.

[–] vrkr@programming.dev 8 points 1 year ago* (last edited 1 year ago)

No reason to go beyond simple key-value format like dotenv or just env variables. If you need more structure then maybe you are confusing configuration with state and this is not really the same thing.

[–] Andy@programming.dev 8 points 1 year ago (1 children)

https://nestedtext.org/

It's like yaml but simple, consistent, untyped, and you never need to escape any characters, ever.

Types and validation aren't going to be great unless they're in the actual code anyway.

[–] MNByChoice@midwest.social 8 points 1 year ago

The one with a validator provided to the user.

[–] Edo78@feddit.it 6 points 1 year ago

It really depends. I usually prefer json. It's easily understandable from humans and from machines, it doesn't depends on indentation and above everything else I like it very much 🤣

[–] philm@programming.dev 5 points 1 year ago* (last edited 1 year ago)

Depends on what you mean exactly with "file format".

If declarative functional programming falls under that, I think something like Nickel, the already mentioned Dhall or Nix. Though Nix more so for packaging and some kind of system management (NixOS?), it's not easily embeddable into a runtime (your app?). Nickel or Dhall is better for that, as they are built from ground up with that in mind, Nickel is maybe the successor of Nix as it is inspired by Dhall and Nix (one goal is to use Nickel as frontend).

The reason why I recommend a simple declarative language, is that they are IMHO much better composable as it lets the user hide boilerplate via functions. I almost always feel limited by static configuration formats like yaml, json etc..

[–] BitSound@lemmy.world 5 points 1 year ago (1 children)
[–] Hexarei@programming.dev 2 points 1 year ago (1 children)

Bruh. I want to use this for my dotfiles. Thanks for sharing it!

[–] philm@programming.dev 2 points 1 year ago (1 children)

You might want to checkout NixOS (or home-manager if you don't want a cold deep dive into a rabbit-hole).

[–] Hexarei@programming.dev 2 points 1 year ago (1 children)

You're probably right I have checked it out, but so far home-manager was a bit of a cold shower to me. I had a ton of trouble wrapping my head around which parts of what config should be responsible for what - and lots of the documentation seems to either be out of date or relying on thing that are still in the 'testing' stage?

I'm interested, but so far just found it frustrating.

load more comments (1 replies)
[–] bignavy@programming.dev 5 points 1 year ago (1 children)
[–] kersplort@programming.dev 4 points 1 year ago (1 children)

XML would be great if it wasn't for the extended XML universe of namespaces and imports.

[–] randomblock1@lemmy.world 3 points 1 year ago

Need it to be user editable in a text editor? YAML. Otherwise, JSON.

[–] footfaults@hexbear.net 2 points 1 year ago

I think it's YAML.

I'm not happy that it's YAML but it's become ubiquitous. Sure, there are lots of other formats that others have mentioned, but I'm sorry most of them are positioned as "it's better than YAML!" and the fact that everyone is mentioning YAML, even if it's about the things it does wrong (and boy does it do things wrong) still means that YAML is on everyone's mind.

[–] greysemanticist@lemmy.one 1 points 1 year ago

Might be somewhat partial to CueLang but that needs an external tool to fiddle with.

I mostly use YAML or TOML depending on what's being configured.

[–] Skyzyx@lemmy.world 1 points 1 year ago

Whatever. Comments are helpful, which makes pure JSON a poor choice. JSON5 or JSON-C are better, but linting and static analysis are important to every form of code, so make sure that what you use for that will understand your syntax.

My current preference is generally TOML, but I've started dabbling with custom HCL2 DSLs. (I write a lot of Go and Terraform.)