python-3.xiniconfigparserpython-config

How to retrieve key, value from config.ini?


i want to read certain data from a config file as key,value

i found below way to define the key value in config.ini

[Section]
value={"name":"John","id":"101"}

but not seeing the way to parse this value as dictionary in python i actually need to retrieve each key value from 'Section value'

Any right solution to this?


Solution

  • You can read the value as usual string then parse it with json package

    import configparser
    import json
    
    config = configparser.ConfigParser()
    config.read('config.ini')
    string = config['Section']['value']
    obj = json.loads(string)