I have a JSON configuration file that looks like this:
{
"container":{
"image":"reporting_engine",
"name":"reporting_engine",
"version":"0.01",
"network":{
"host":{
"ip":"127.0.1.1",
"port":"5000"
},
"container":{
"ip":"127.0.1.1",
"port":"5000"
}
},
"storage":{
"host":"/home/scaldwell/rpe/data",
"container":"/opt/app/data"
}
}
}I want to read this JSON configuration file into a Python object so I can address properties in an intuitive way programmatically.
I realize I could do something like this:
import json
with open(config_file,'r') as f:
config=json.loads(f.read())and then use my configuration parameters like this:
print config["network"]["host"]["ip"]
While that is acceptable Python, it's about as elegant as a Trump speech and possibly just as likely to have errors since there all of those open and closing brackets and quotes.
I would rather a solution that allows me to do the same print like this:
print config.network.host.ip
...like a civilized code monkey. 