arraylist to json - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: arraylist to json (/thread-34704.html) |
arraylist to json - soonyu - Aug-23-2021 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 RE: arraylist to json - soonyu - Aug-23-2021 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": {}}} |