I have 2 json files! f1.json and f2.json
Contents: "f1.json"
{
"tests":
[
{"a": "one", "b": "two"},
{"a": "one", "b": "two"}
]
}
Contents: "f2.json"
{
"tests":
[
{"c": "three", "d": "four"}
]
}
Required output - in list format
[{a:"one",b:"two"},{a:"one",b:"two"},{c:"three",d:"four"}]
I'm getting the same output in the "unicode" format. Does anyone have a way to get it without the unicode?
My output
[{u'a': u'one', u'b': u'two'}, {u'a': u'one', u'b': u'two'}, {u'c': u'three', u'd': u'four'}]
Code:
files=['t1.json','t2.json']
import json,ast
empty = []
for elements in files:
fh = open(elements, 'r')
filedata = fh.read()
fh.close()
data = json.loads(filedata)
empty.append(data['tests'])
final = []
for elements in empty:
for dict in elements:
final.append(dict)
print final