using simplejson.dumps to encode a dictionary to json
MRAB
python at mrabarnett.plus.com
Tue Mar 15 16:25:41 EDT 2011
On 15/03/2011 19:56, Aaron wrote:
> If I print authreq_data to screen I get
>
> {"req": {"username": "######", "password": "#####", "productType": "CFD_Demo"}}
>
> Essentially I want the inner brackets to be [ ] instead of {} but alternating on each level so it would be:
>
> {"req": [{"username": "######", "password": "#####", "productType": "CFD_Demo"}]}
>
> as per usual json.
>
{... } designates a dict and [...] designates a list.
If you give json the correct structure then it will give you want you
want.
This is a dict:
{"req": [{"username": "######", "password": "#####", "productType":
"CFD_Demo"}]}
The value for the key "req" is a list:
[{"username": "######", "password": "#####", "productType":
"CFD_Demo"}]
which contains a dict:
{"username": "######", "password": "#####", "productType": "CFD_Demo"}
More information about the Python-list
mailing list