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

  • Home
  • SEARCH
  • 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 9234487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:48:05+00:00 2026-06-18T06:48:05+00:00

I have a python dictionary of JSON serialized values. I want to add to

  • 0

I have a python dictionary of JSON serialized values.

I want to add to these serialized strings without first doing loads(...), then later doing dumps(...) – so I ‘fiddle’ with the serialized values:

currently I have:

for key, value in my_dict.items():
    # creating JSON of additional data I want in the JSON string
    extra = dumps({ 'key1': 3, 'key2': 1 }, default=str)

    # cutting the last '}' from the end off 'value', the '{' and '}' from the
    # start and end of 'extra', and then concatting them together.
    my_dict[key] = '%s,%s' % (value[:-1], extra[1:])

I am doing this because I consider the dumps and loads a waste, but my current method is not very pythonic.

Is there a better method?

Note: the ‘extra’ values are from a different source to the initial JSON values, and cannot be inserted at the point where the original data was serialized.

time differences when using a dict of ~20 JSON blobs:

  • fiddling: 0.0005 seconds
  • json>py>json: 0.0025 seconds

5 times quicker

and for fun with 20,000:

  • fiddling’: 0.333
  • json>py>json: 0.813

over 60% quicker

with 200,000:

  • fiddling’: 4.5
  • json>py>json: 10.25

over 60% quicker

  • 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-06-18T06:48:06+00:00Added an answer on June 18, 2026 at 6:48 am

    The Pythonic way would be to parse the JSON string, modify the values then serialize it. JSON is very quick to parse, much faster than the standard pickle/unpickle functions, and will probably not slow you down unless you have enormous amounts of data (tens of thousands of lines). Don’t fall into the trap of optimizing prematurely.

    In any case, you should always write your application in a nice, Pythonic and readable fashion, then (if necessary!) optimize the slow parts of your code later.


    Another method of optimization could be to write the relevant code in C, or use a C library for JSON serialization. Take a look at ultrajson or take a look at this answer, which explains how the standard library simplejson can be much faster than the json module you are using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process that pickles a dictionary using Python 3.2. I then need
Possible Duplicate: Python dictionary, keep keys/values in same order as declared If I have
I have followed this How do I JSON serialize a Python dictionary? and this
I have a python dictionary consisting of JSON results. The dictionary contains a nested
I have a dictionary in Python that I would like to serialize in JSON
I have a python dictionary of type defaultdict(list) This dictionary is something like this:
I have data in a python dictionary that I'd like to store in a
I have a python function that randomize a dictionary representing a position specific scoring
I'm newish to Python (and stackoverflow)...bear with me! I have a dictionary that looks
I have a python dictionary like this {'OR': [{'AND': [{'column': 'XXX', 'operator': '=', 'value':

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.