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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:20:05+00:00 2026-06-11T15:20:05+00:00

Importing from JSON can get very complex and nested structures. For example: {u’body’: [{u’declarations’:

  • 0

Importing from JSON can get very complex and nested structures.
For example:

{u'body': [{u'declarations': [{u'id': {u'name': u'i',
                                       u'type': u'Identifier'},
                               u'init': {u'type': u'Literal', u'value': 2},
                               u'type': u'VariableDeclarator'}],
            u'kind': u'var',
            u'type': u'VariableDeclaration'},
           {u'declarations': [{u'id': {u'name': u'j',
                                       u'type': u'Identifier'},
                               u'init': {u'type': u'Literal', u'value': 4},
                               u'type': u'VariableDeclarator'}],
            u'kind': u'var',
            u'type': u'VariableDeclaration'},
           {u'declarations': [{u'id': {u'name': u'answer',
                                       u'type': u'Identifier'},
                               u'init': {u'left': {u'name': u'i',
                                                   u'type': u'Identifier'},
                                         u'operator': u'*',
                                         u'right': {u'name': u'j',
                                                    u'type': u'Identifier'},
                                         u'type': u'BinaryExpression'},
                               u'type': u'VariableDeclarator'}],
            u'kind': u'var',
            u'type': u'VariableDeclaration'}],
 u'type': u'Program'}

What is the recommended way to walk complex structures like the above?

Apart of a few list there are mostly dictionaries, the structure can become even more imbricated so I need a general solution.

  • 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-11T15:20:06+00:00Added an answer on June 11, 2026 at 3:20 pm

    You can use a recursive generator for converting your dictionary to flat lists.

    def dict_generator(indict, pre=None):
        pre = pre[:] if pre else []
        if isinstance(indict, dict):
            for key, value in indict.items():
                if isinstance(value, dict):
                    for d in dict_generator(value, pre + [key]):
                        yield d
                elif isinstance(value, list) or isinstance(value, tuple):
                    for v in value:
                        for d in dict_generator(v, pre + [key]):
                            yield d
                else:
                    yield pre + [key, value]
        else:
            yield pre + [indict]
    

    It returns

    [u'body', u'kind', u'var']
    [u'init', u'declarations', u'body', u'type', u'Literal']
    [u'init', u'declarations', u'body', u'value', 2]
    [u'declarations', u'body', u'type', u'VariableDeclarator']
    [u'id', u'declarations', u'body', u'type', u'Identifier']
    [u'id', u'declarations', u'body', u'name', u'i']
    [u'body', u'type', u'VariableDeclaration']
    [u'body', u'kind', u'var']
    [u'init', u'declarations', u'body', u'type', u'Literal']
    [u'init', u'declarations', u'body', u'value', 4]
    [u'declarations', u'body', u'type', u'VariableDeclarator']
    [u'id', u'declarations', u'body', u'type', u'Identifier']
    [u'id', u'declarations', u'body', u'name', u'j']
    [u'body', u'type', u'VariableDeclaration']
    [u'body', u'kind', u'var']
    [u'init', u'declarations', u'body', u'operator', u'*']
    [u'right', u'init', u'declarations', u'body', u'type', u'Identifier']
    [u'right', u'init', u'declarations', u'body', u'name', u'j']
    [u'init', u'declarations', u'body', u'type', u'BinaryExpression']
    [u'left', u'init', u'declarations', u'body', u'type', u'Identifier']
    [u'left', u'init', u'declarations', u'body', u'name', u'i']
    [u'declarations', u'body', u'type', u'VariableDeclarator']
    [u'id', u'declarations', u'body', u'type', u'Identifier']
    [u'id', u'declarations', u'body', u'name', u'answer']
    [u'body', u'type', u'VariableDeclaration']
    [u'type', u'Program']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am importing JSON data from a public database URI http://data.seattle.gov/api/views/3k2p-39jp/rows.json and the rows
I have an app that is importing data from JSON and generating (through JQuery's
Im importing some data from JSON , i have the values in a enumeration
I'm importing some tweets using the Search API and get the returning JSON: results:
We are importing from CSV to SQL. To do so, we are reading the
I'm importing from a CSV and getting data roughly in the format { 'Field1'
NSString is returning as NULL while Importing from ViewController Class were i want to
I am looking for any tips or resources on importing from excel into a
After importing content from a legacy website using the Feeds module, I'm left with
I am importing data from MySQL to PowerPivot. I have all of the relevant

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.