[ACCEPTED]-Combining two JSON objects in to one-json

Accepted answer
Score: 22

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)
Score: 6

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)
Score: 0

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)

More Related questions