[ACCEPTED]-Combining two JSON objects in to one-json
Accepted answer
You can't do it once they're in JSON format 2 - JSON is just text. You need to combine 1 them in Python first:
data = { 'obj1' : obj1, 'obj2' : obj2 }
json.dumps(data)
Not sure if I'm missing something, but I 2 think this works (tested in python 2.5) with 1 the output you specify:
import simplejson
finalObj = { 'obj1': obj1, 'obj2': obj2 }
simplejson.dumps(finalObj)
You have two techniques. The list version 4 suffers from the limitation that the order 3 matters. However, the JSON is slightly 2 simpler-looking. The dictionary version 1 has nested data, which looks more complex.
data = { 'obj1' : obj1, 'obj2' : obj2 }
json.dumps(data,indent=2)
data = [ obj1, obj2 ]
json.dumps(data,indent=2)
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.