.yaml, .toml, etc?
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.)
Submitted 1 year ago by likeaduck@programming.dev to experienced_devs@programming.dev
.yaml, .toml, etc?
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.)
Oh that’s interesting. Wonder how many libraries out there support it…
I don’t know if it’s actual json5, but eslint and some other libraries use extended, commentable json in their config files.
The one with a validator provided to the user.
A lot of good answers but I would add one note:
Of course it does!
{ comment: "This data is super important and it runs the system or something", data: ["Some", "stuff", "here"] }
You disgust me
How do you comment multiple properties separately?
This is actually pretty genius, why haven’t ever thought of that?
JSON5 is a superset of JSON that supports comments.
I believe the JSON deserializer .NET ships with has options to allow C#-style comments in JSON files.
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)
It depends what you need your configuration file to be:
Need a well defined easy to understand concrete configuration file?
.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?
.json
. It’s famous for being so simple it’s Need an abstract configuration file for more complicated setups?
.ncl
. Nickle allows you to define functions so that you can generate/compute the correct configuration by changing a few variables/flags..ini
ducks
Give the windows registry a shot.
Yaml for me, I really like it. And the fact that every valid JSON is also a valid YAML is nice.
Please do not use YAML. It’s a syntactic minefield. It also doesn’t allow tab indentation, which is supremely irritating.
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.
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.
Easily the format no one’s heard of that you jammed together in your attic when you were twelve.
No reason to go beyond simple key-value format like dotenv or just env variables. If you need more structure you may be confusing configuration with state and this is not really the same thing.
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.
Agreed.
I honestly don’t understand anyone who likes json over it. Json is fine for certain things but manually typing that is pain ten times over. It’s better than XML surely but not by terribly much.
Bruh. I want to use this for my dotfiles. Thanks for sharing it!
You might want to checkout NixOS (or home-manager if you don’t want a cold deep dive into a rabbit-hole).
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 🤣
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 it Nickel as frontend).
The reason why I recommend a simple declarative language, is that that they are 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…
XML would be great if it wasn’t for the extended XML universe of namespaces and imports.
AKA “The XML Cinematic Universe”
Need it to be user editable in a text editor? YAML. Otherwise, JSON.
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.)
Tyson is nice - esp. if you are already using TS/JS.
AverageCakeSlice@sh.itjust.works 1 year ago
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.
Hexarei@programming.dev 1 year ago
Yeah, any language in which whitespace count is semantically significant can go suck fat nards.
derpgon@programming.dev 1 year ago
I mean, a valid JSON is a valid YAML
bignavy@programming.dev 1 year ago
Not sure whether fantastic troll or just no exposure to Python.
Either way…I’m here for it.
sylveon@programming.dev 1 year ago
The only thing that really annoys me about JSON is that it doesn’t allow comments.
Hexarei@programming.dev 1 year ago
JSON5, bay-beee
nightmareofahorse@programming.dev 1 year ago
GitHub Actions and Azure DevOps had me hating on YAML pretty quickly
kersplort@programming.dev 1 year ago
YAML works better with git than JSON, but so much config work is copy and pasting and YAML is horrible at that.
Having something where changing one line doesn’t turn into changing three lines, but you could also copy it off a website would be great.