how do you create an automatic mapping of possible json data options to be collected?

If the elements in the events arrays are the same, this code works without errors.

def get_prints(recode: dict):
    for key in recode.keys():
        if type(recode[key]) == dict:
            for sub_print in get_prints(recode[key]):
                yield [key] + sub_print
            yield [key]

class Automater:
    def __init__(self,name: str):
            name: name of json
        """ = name

    def get_print(self,*args):
            *args: keys json
        return '_'.join(args) + ' = ' + + ''.join([f"['{arg}']" for arg in args])

For example, this code:

dicts = {
        'name':"any name",
        'slug':'somthing else',
list_names = get_prints(dicts)
for name in list_names:

Gives this output:

tournament_name = event['tournament']['name']
tournament_slug = event['tournament']['slug']
tournament_sport_name = event['tournament']['sport']['name']
tournament_sport_anotherdict_yes = event['tournament']['sport']['anotherdict']['yes']

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top