Serializing data to JSON in python -


can give me guidelines how serialize data file similar presented below?

{   "minshift": -0.5,   "maxshift": 0.5,   "stepshift": 0.002,   "feeds": {     "cfh": "cfh_20140318t0900.txt",     "lmax": "lmax_20140318t0900.txt",     "saxo": "saxo_20140318t0900.txt"   },   "instruments": [       {         "instrument_old": "cfh/eurusd",         "instrument_new": "lmax/eurusd"       },       {         "instrument_old": "cfh/eurusd",         "instrument_new": "saxo/eurusd"        },       {         "instrument_old": "lmax/xauusd",         "instrument_new": "saxo/xauusd"        }   ] } 

i have:

  • shiftdata list 3 elements (for min, max , stepshift)
  • dictionary key:value => {provider_name : filename}
  • list of 2 element lists [instrument_new, instrument_old] named instrumentpairlist

i don't want nobody solve task, various tutorials on json in python rather blurred or simple in case:

it trying serializing minshift, maxshift, stepshift , feeds:

data = { "minshift":shiftdata[0],"maxshift":shiftdata[1],"stepshift":shiftdata[2],           "feeds":[ {key: value} key, value in provideraliases.items() ] }   data_string = json.dumps(data) 

my solution is:

data = { "minshift":shiftdata[0],"maxshift":shiftdata[1],"stepshift":shiftdata[2],           "feeds":provideraliases,            "instruments":[ {"instrument_old":pair[0],"instrument_new":pair[1]}                             pair in instrumentpairlist ]} data_string = json.dumps(data, indent=4)  file = open(dir+r"\config.json","w") file.write(data_string) file.close() 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -