How to merge multiple json objects into a single json object using python

0 votes

I have a list which contains multiple JSON objects and I would like to combine those JSON objects into a single json object, I tried using jsonmerge but with no luck.

My list is:

t = [{'ComSMS': 'true'}, {'ComMail': 'true'}, {'PName': 'riyaas'}, {'phone': '1'}]

The desired output is

t = [{'ComSMS': 'true', 'ComMail': 'true', 'PName': 'riyaas', 'phone': '1'}]

I put the list in a for loop and tried json merge and I got the error head missing expected 2 arguments got 1

Can someone help me solve this issue

Nov 22, 2020 in Python by Roshni
• 10,480 points
19,329 views

1 answer to this question.

0 votes

You may do like this but it should not be in order.

>>> t = [{'ComSMS': 'true'}, {'ComMail': 'true'}, {'PName': 'riyaas'}, {'phone': '1'}]
>>> [{i:j for x in t for i,j in x.items()}]
[{'ComSMS': 'true', 'phone': '1', 'PName': 'riyaas', 'ComMail': 'true'}]


I am sure this helped to answer your query, cheers!

For more, join this course to Master Python programming.

Thanks!

answered Nov 22, 2020 by Gitika
• 65,770 points

Related Questions In Python

0 votes
0 answers

How to implement multiple try codes in a single block using Python?

Hi all, As per the title, I am ...READ MORE

Jan 14, 2019 in Python by Anirudh
• 2,090 points
666 views
0 votes
1 answer

How to convert JSON data into a Python object?

Hello @kartik, You can do it in one ...READ MORE

answered Aug 3, 2020 in Python by Niroj
• 82,840 points
2,230 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
3,458 views
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31, 2020 in Python by MD
• 95,460 points
1,135 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,069 views
0 votes
3 answers

How to get the return value from a thread using python?

FWIW, the multiprocessing module has a nice interface for ...READ MORE

answered Dec 15, 2020 in Python by Roshni
• 10,480 points
107,743 views
0 votes
4 answers

How to print objects of class using print function in Python?

>>> class Test: ... ...READ MORE

answered Dec 16, 2020 in Python by Roshni
• 10,480 points
78,510 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP