I am trying to follow the answer(s) in the question shown here, but I'm still having some trouble combining my two json objects.
I have two JSON objects which are returned from a web call and I'm storing them in variables called: likes_data and comments_data. Each of these are currently empty JSON objects (in my test cases only) and when printed to the screen show: {"data":[]}.
Now I would like to combine these two (sometimes empty) JSON objects into a single object and print it to the screen, but I'm having some trouble because the final combined object always has escaped quotes in it.
The code:
data = { 'likes' : likes_data, 'comments' : comments_data }
self.response.out.write(json.dumps(data))
results in:
{
"likes": "{\"data\":[]}",
"comments": "{\"data\":[]}"
}
which is obviously an incorrectly formatted JSON response because of the escaped quotations.
Is there a proper way to combine two JSON objects in Python? for the simple case, I can manually unescape these, but I'd like to be able to manage "data" objects which are more complex.
Does anyone have any advice?
Cheers, Brett
likes_dataandcomments_dataand then put them intodataas objects?JSONis javascript object notation allowing data to be transmitted over a network or two different systems, it is transmitted as text and it is text to all other languages. You should convert json data to a python object and do your things, then encode it into json before you send; fee Fabian's example.