Python: using ConfigParser vs json file

I am currently using the ConfigParser module to read and analyze the configuration for a python program. I understand that using ConfigParser makes it easier to parse and read the configuration from the file, however, I'm just wondering what the trade-offs would be if I just use the json format to read / write configuration files. Wouldn't it be equally easy to make out, etc. Just like ConfigParser?

+4
source share
1 answer

JSON will be lightweight enough for your program to parse, but it would also make the user responsible for getting the brackets and quotes just right, and that would add unnecessary clutter to your configuration files. If this extra complexity is fine with you or you really need a deep nesting that is a little easier to parse in JSON than in flat configuration files, then by all means, use JSON. Some people even do it even further and put their configuration in Python files.

Personally, I believe that configuration files that users can read or edit should be as simple as possible, so I use (a subset) of the configparser syntax. If I need a hierarchy, I just represent it with dots:

parent.child1 = foo
parent.child2 = bar
+4

All Articles