On Software: Configuration

These are a few thoughts (from the point of view as an user and also as a developer) on handling configuration data for [application] software.

Enable to import/export settings

As an user (and also administrator), I really like it when applications offer (easily detectable and usable!) ways to export and import its settings:
I still use many programs which are installed and configured locally and once the program is customized to my liking (e.g. keyboard shortcuts, fonts, GUI adjustments, etc.), I want to save that work, in case the program needs to be set up again on another machine (be it a second computer or a replacement for a damaged device).

When such a feature is not available (or simply not documented), I try to help myself by using workarounds like manually copying files from the user’s home directory (e.g. under %AppData% or other places) or from the program folder; sometimes even dumping registry values).
But that is of course not an optimal solution, because then I always have the nagging feeling: “Is that all? Or are there more settings stored somewhere else on my system?”.

In general I’d prefer single files in text format (instead of binary blobs), but I also know that this is sometimes not possible, and that some programs (need to) use directories with multiple files in different formats in it (also known as “profiles”).

The bottom line is that ideally a program should offer something like Settings → Export… and Settings → Import… to generate/select configuration formats (files or folders). And it’s also a good idea to offer it via a command-line interface: That can also come in handy if one needs to build automatic and unattended installation scripts for software deployment.

File format for storing configuration data

As an user, I’d prefer to be able to export/import and keep my preferences & settings in a distinct unit, separate from the actual software; ideally as something that resolves to text files (some assets may need to be stored in binary, but I’m talking about a general case here).

There are a lot of formats for saving and exchanging configuration and data; but I will only go into some details for INI, XML and JSON, because although I’m aware of the newer formats like TOML or YAML, I don’t think that they offer anything significantly different from the more common formats mentioned before.

Quick comparison and reasoning

For very simple settings, I may use still the INI format, but for more elaborate stuff, I would try my luck with JSON, since XML is in my opinion too complicated and verbose, at least for elementary things.

JSON Sample Data

{
    "Key 1" : "Some random string value",
    "Key 2" : 100,
    "Key 3" : 1.5,
    "Key 4" : true,
    "Key 5" : false,
    "Key 6" : null,
    
    "Key 7":
    [
        1,
        "abc",
        15.25,
        {
            "Entry A": 256,
            "Entry B":
            {
                 "a": 1,
                 "b": "foo",
                 "c": ["abc", "def"]
            }
        }
    ],
    
    "Product Information":
    [
        0,
        { "xyz" : 1 },
        3,
        
        {
            "Value 1": "Blah blubb",
            "Value 2": "Blah blubber",
            
            "Products":
            [
                [
                    "Item 1",
                    "Item 2",
                    "Item 3"
                ],
                
                [
                    "Item A",
                    "Item B",
                    "Item C"
                ],
                
                {
                    "Details":
                    [
                        {
                            "Name"       : "Foo",
                            "Version"    : 1,
                            "Description": "A short description of product \"Foo\"."
                        },
                        
                        {
                            "Name"       : "Bar",
                            "Version"    : 1,
                            "Description": "A short description of product \"Bar\"."
                        }
                    ]                
                }
            ]
        },
        
        "ABC",
        2,
        9999
    ]
}

Remarks