Is using something other than XML advisable for the configuration file

configurationfile structurejsonnetxml

I have a small tool I'm designing which would require a configuration file of some sort. The configuration file in my case is really more of a database, but it needs to be lightweight, and if needed the end-user should find it easily editable. However, it also will contain a lot of things in it. (depending on certain factors, could be 1Mb or more)

I've decided I'd rather use plain ol' text, rather than trying to use SQLite or some such. However, with using text, I also have to deal with the variety of formats. So far, my options are

  • XML
  • JSON
  • Custom format

The data in my file is quite simple consisting for the most part of key-value type things. So, a custom format wouldn't be that difficult… but I'd rather not have to worry about writing the support for it. I've never seen JSON used for configuration files. And XML would bloat the file size substantially I think. (I also just has a dislike of XML in general).

What should I do in this case?

Factors to consider:

  • This configuration file can be uploaded to a web service(so size matters)
  • Users must be able to edit it by hand if necessary(ease of editing and reading matters)
  • Must be able to generate and process automatically (speed doesn't matter a lot, but not excessively slow)
  • The "keys" and "values" are plain strings, but must be escaped because they can contain anything. (unicode and escaping has to work easily)
  • Multiple configuration files. Basically, each config file is tied to one "project"

Best Answer

I think YAML is best fit for your case. To my understanding, YAML is the de facto standard format for configuration files that need to be edited by hand. Many programming languages have a library for reading and/or writing YAML. JSON is closely related to YAML, but is little bit less easier to write than YAML, and is used more for communication between web server and the client program.

Related Topic