yadunath.narayanan
yadunath.narayanan

Reputation: 285

Merging Json response Django python

I am writing a django server api,where I have two request to fetch data from two other apis.

list1 = requests.get(f"www.test.com/list/")
list2 = requests.get(f"www.test.com/list2/")

this two lists have json as response.I want to merge this two and put it in a json object like below

{"list1":list1,"list2":list2}

and return the result

Upvotes: 2

Views: 448

Answers (1)

omid
omid

Reputation: 842

json built-in package will do the job for you.

import json


list1 = json.loads(your_json_response1)
list2 = json.loads(your_json_response2)

your_response = {
    'list1': list1,
    'list2': list2,
}

your_json_response = json.dumps(your_response)

Upvotes: 2

Related Questions