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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:47:33+00:00 2026-05-15T15:47:33+00:00

Is there some kind of enumeration library or method I should use or should

  • 0

Is there some kind of enumeration library or method I should use or should I write from scratch with recursion?

I’m parsing a JSON tree into an object tree as it happens, and I’d like to replace some nodes with other kinds of objects.

E.g:

db = {'bigBang' :
          {'stars':
               {'planets': {}, 'is_list':true
               }
           }
     }
db.deepReplace( 'is_list', ['earth', 'mars'] )
>> db is now: 
>> {'bigBang' :
>>        {'stars':
>>             {'planets':
>>                 {
>>                     ['earth', 'mars']
>>                 }
>>             }
>>         }
>> }
  • 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-15T15:47:33+00:00Added an answer on May 15, 2026 at 3:47 pm

    If you know there’s only one node to replace:

    def deepReplace(d, key, value):
        if isinstance(d, dict):
            if key in d:
                d[key] = value
                return True
            else:
                for k,v in d.iteritems():
                    if deepReplace(v, key, value):
                        return True
        return False
    

    Otherwise:

    def deepReplace(d, key, value):
        if isinstance(d, dict):
            if key in d:
                d[key] = value
            else:
                for k,v in d.iteritems():
                    deepReplace(v, key, value):
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some kind a engine for Json in the Zend framework, What I
Is there some kind of wildcard I can use to create POST vars that
Is there some kind of a tool or some better output from javac to
Is there some kind of not CSS selector? For example when I write the
Is there some kind of class / method / technique that allows to automatically
Is there some kind of bean factory or static class that I can use
Is there some kind of a shorthand fluent interface for creating a parameters dictionary
Surely there is some kind of abstraction that allows for this? This is essentially
I was wondering if there was some kind of J tool in the java
I'm wondering if there's some kind of criteria that can be used to determine

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.