Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3455156
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:34:47+00:00 2026-05-18T09:34:47+00:00

How do I serialize a Python dictionary into a string, and then back to

  • 0

How do I serialize a Python dictionary into a string, and then back to a dictionary? The dictionary will have lists and other dictionaries inside it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:34:48+00:00Added an answer on May 18, 2026 at 9:34 am

    It depends on what you’re wanting to use it for. If you’re just trying to save it, you should use pickle (or, if you’re using CPython 2.x, cPickle, which is faster).

    >>> import pickle
    >>> pickle.dumps({'foo': 'bar'})
    b'\x80\x03}q\x00X\x03\x00\x00\x00fooq\x01X\x03\x00\x00\x00barq\x02s.'
    >>> pickle.loads(_)
    {'foo': 'bar'}
    

    If you want it to be readable, you could use json:

    >>> import json
    >>> json.dumps({'foo': 'bar'})
    '{"foo": "bar"}'
    >>> json.loads(_)
    {'foo': 'bar'}
    

    json is, however, very limited in what it will support, while pickle can be used for arbitrary objects (if it doesn’t work automatically, the class can define __getstate__ to specify precisely how it should be pickled).

    >>> pickle.dumps(object())
    b'\x80\x03cbuiltins\nobject\nq\x00)\x81q\x01.'
    >>> json.dumps(object())
    Traceback (most recent call last):
      ...
    TypeError: <object object at 0x7fa0348230c0> is not JSON serializable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary in Python that I would like to serialize in JSON
I have a web service that uses Python's SimpleJSON to serialize JSON, and a
I am able to serialize an object into a file and then restore it
I'm looking for a way to serialize generic Python objects between a CherryPy-based server
When I serialize; public class SpeedDial { public string Value { get; set; }
I'm currently writing a serialization module in Python that can serialize user defined classes.
I'm writing a python server/client app. If I serialize a function on the client
I have a querystring like a=2&b=3 created by serialize() jQuery. How to get a
I'm trying to serialize a Type object in the following way: Type myType =
I would like to serialize and deserialize objects without having to worry about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.