Ben’s mumbling

You can prove anything with facts.

JSON and the Arguments

What’s the beef with JSON?

So recently, I may have been shouting about JSON and how you shouldn’t use it for configuration files and using the right language tool for the job. So what’s my big problem with JSON? Well actually I don’t have a problem with JSON. JSON has freed us mostly from XML, and the horrors of SOAP.

If you’re writing a webapp, you’re rocking some REST, then JSON is great (though msgpack is better if care about performance). So why am I shouting? Well, it’s because HUMANS SHOULD NOT BE WRITING JSON so please stop using it for configuration files!

I don’t want to pick on projects I like, (Sorry @jordansissel, I love your work you just document this fact) but Lumberjack for example even points this out in their documentation example. You can’t put comments in it, I can’t help but feel that’s hostile towards the consumers of the software. You know people want comments, it only makes sense with comments, but JSON. Imagine writing code without comments (no no, good code, code you’d share), I don’t see configuration files as all that different.

Chef does the same, why are there so many .json files? To make it easier for the delevopers of Chef? To make it easier for the chef-server? At whose expense? Oh just the majority of people. YAML I kinda disliked until I was thrust in to using a marshalling language as if it was configuration data…language as if it was configuration data…language as if it was configuration data…

A tonne of people suggested running it through a pre-processor. I say to you, “Those who forget the past are doomed to repeat it.”

Also, in the world of 2014, we have this thing called configuration management now. Have you tried tempesting JSON. For sure, you can just JSON.pretty_generate() in to the file, should you need to, but you don’t make any other config files that way.

The hostility of the following:

1
2
3
4
5
6
7
{
    "array": [
        "one",
        "two",
        "three",
    ]
}

That’s fine right? Oh no, there’s a trailing comma, so the world blows up.

Replacing it

Many people have since pointed me at HOCON which seems like a lovely compromise, but people need to use it, though I still don’t think it’s the right thing to do.

I voiced my support for .ini, yes that ini from Windows… I know, it’s crazy talk. I don’t think it’s perfect, but the benefits of it are:

  • Python stdlibs supports it
  • It’s simple to read for a human or a fangled adding machine.
  • You can template that in anything, even bash.
  • You can grep it!

I don’t think it’s perfect, and I’d like to hear other options. I don’t think Apache’s file format is great, nginx’s is a little better but not great.

Please, flame me in the comments, or shout at me on Twitter.

Comments