I am new to python, am used to php, and I am trying to figure out how to combine the json.loads from multiple data sets into one.
This is what I have:
import json
var = json.loads('{"root": [{"item 1": "1","item 2": "2","List1": [1,2,3]}]}')
var2 = json.loads('{"root": [{"item 1": "1","item 2": "2","List2": [1,2,3]}]}')
import pprint
print 'var:'
pprint.pprint(var);
print 'var2:'
pprint.pprint(var2);
print 'deepcopy:'
import copy;
var3 = var;
var3 = copy.deepcopy(var2);
pprint.pprint(var3);
print 'dict copy:'
pprint.pprint(dict(var.items() + var2.items()));
Results in:
var: {u'root': [{u'List1': [1, 2, 3], u'item 1': u'1', u'item 2': u'2'}]}
var2: {u'root': [{u'List2': [1, 2, 3], u'item 1': u'1', u'item 2': u'2'}]}
deepcopy: {u'root': [{u'List2': [1, 2, 3], u'item 1': u'1', u'item 2': u'2'}]}
dict copy: {u'root': [{u'List2': [1, 2, 3], u'item 1': u'1', u'item 2': u'2'}]}
I am looking for a result like (including both lists), but including the duplicate items would be helpful as well, as then I will be heading in the right direction:
{u'root': [{u'List1': [1, 2, 3], u'List2': [1, 2, 3], u'item 1': u'1', u'item 2': u'2'}]}