Can somebody give me some guidelines how to serialize data to file similar to 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 with three elements (for min, max and stepShift)
- dictionary with key:value => {provider_name : filename}
- list of two element lists [instrument_new, instrument_old] named instrumentPairList
I don't want nobody to solve my task, but various tutorials on JSON in Python are rather blurred or to simple in my case:
- http://pymotw.com/2/json/
- https://python.readthedocs.org/en/v2.7.2/library/json.html
- http://freepythontips.wordpress.com/2013/08/08/storing-and-loading-data-with-json/
- Python dump dict to json file
- http://www.anthonydebarros.com/2012/03/11/generate-json-from-sql-using-python/
It is trying to serializing minShift, maxShift, stepShift and feeds:
data = { "minShift":shiftData[0],"maxShift":shiftData[1],"stepShift":shiftData[2],
"feeds":[ {key: value} for key, value in providerAliases.items() ] }
data_string = json.dumps(data)