Python Forum

Full Version: arraylist to json
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
look for help for the below:
i have list of item in array;
for row  in rows:
        t=(row[0])
        rowarray_list.append(t)
when convert to key value
j_string=','.join(rowarray_list)
j=json.dumps({"_meta":{ "hostvars":{}},"instances":{"hosts":[j_string],"vars":{}}})
it give me
{"_meta": {"hostvars": {}}, "instances": {"hosts": ["abc,efg"], "vars": {}}}
instead
{"_meta": {"hostvars": {}}, "instances": {"hosts": ["abc","efg"], "vars": {}}}
Thanks in advance
i should not convert to string... :)

for row in rows:
t=(row[0])
rowarray_list.append(t)


j=json.dumps({"_meta":{ "hostvars":{}},"instances":{"hosts":rowarray_list,"vars":{}}})


{"_meta": {"hostvars": {}}, "instances": {"hosts": ["abc","efg"], "vars": {}}}