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 9293807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:13:40+00:00 2026-06-18T21:13:40+00:00

I am parsing JSON that stores various code snippets and I am first building

  • 0

I am parsing JSON that stores various code snippets and I am first building a dictionary of languages used by these snippets:

snippets = {'python': {}, 'text': {}, 'php': {}, 'js': {}}

Then when looping through the JSON I’m wanting add the information about the snippet into its own dictionary to the dictionary listed above. For example, if I had a JS snippet – the end result would be:

snippets = {'js': 
                 {"title":"Script 1","code":"code here", "id":"123456"}
                 {"title":"Script 2","code":"code here", "id":"123457"}
}

Not to muddy the waters – but in PHP working on a multi-dimensional array I would just do the following (I am lookng for something similiar):

snippets['js'][] = array here

I know I saw one or two people talking about how to create a multidimensional dictionary – but can’t seem to track down adding a dictionary to a dictionary within python. Thanks for the help.

  • 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-18T21:13:42+00:00Added an answer on June 18, 2026 at 9:13 pm

    This is called autovivification:

    You can do it with defaultdict

    def tree():
        return collections.defaultdict(tree)
    
    d = tree()
    d['js']['title'] = 'Script1'
    

    If the idea is to have lists, you can do:

    d = collections.defaultdict(list)
    d['js'].append({'foo': 'bar'})
    d['js'].append({'other': 'thing'})
    

    The idea for defaultdict it to create automatically the element when the key is accessed. BTW, for this simple case, you can simply do:

    d = {}
    d['js'] = [{'foo': 'bar'}, {'other': 'thing'}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one application in j2me, I have used json parsing in that
I'm parsing JSON that is contained in an HTML element. Consider this markup: <div
I'm having some trouble parsing a JSON that I obtain from my DB to
The JSON that I am parsing can be found here 'redacted'. I can correctly
i am doing jSon parsing in C# (ASP).The problem is that when the JSON
I'm doing a Json parsing, in that i need to parse the "TStatus" key
I'm looking for a way that json parsing will take information as is (as
I am working with JSON. when I am Passing data for serialization at that
From a previous question on Stackoverflow Iterating through/Parsing JSON Object via JavaScript .... My
I already looked at a similar question here : null pointer exception-parsing json with

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.