How to convert a DictProxy object into JSON serializable dict

0 votes

I have a DictProxy object created using multiprocessing.Manager().dict() to support concurrency. At the end of the run, I need to serialize the dict to JSON. But it's unclear how to convert the DictProxy to serializable dict object. When I tried it, I got:

TypeError: <DictProxy object, typeid 'dict' at 0x10a240ed0> is not JSON serializable

How can I fix this?

Apr 15, 2020 in Python by kartik
• 37,510 points
4,272 views

1 answer to this question.

0 votes

Hello,

Rather than using a private DictProxy method like _getvalue(), I'd prefer using a public one like copy() which returns a shallowly-copied dict.

import multiprocessing

if __name__ == '__main__':
    manager = multiprocessing.Manager()
    d = manager.dict()
    import json
    json.dumps(d.copy())

Hope this work!

Thank You!!

answered Apr 15, 2020 by Niroj
• 82,880 points

Related Questions In Python

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,237 views
0 votes
1 answer

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

You may do like this but it ...READ MORE

answered Nov 22, 2020 in Python by Gitika
• 65,910 points
18,625 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 58,090 points
2,333 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 58,090 points
758 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,058 views
0 votes
1 answer
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,880 points
1,952 views
+1 vote
1 answer

How to convert a PIL Image into a numpy array?

Hello @kartik, You just need to convert your ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,880 points
3,914 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