Comparing two json schemas

Viewed 1016

I'm looking to determine whether two highly nested json objects have the same schema. What I was thinking of doing was to get a list of all keys recursive and compare them. For example:

def get_all_keys_recursively(d, keys=None):
    LIMIT = 400

    if keys is None: keys = []
    if len(keys) >= LIMIT: return keys

    for k, v in d.items():
        if isinstance(v, dict):
          get_all_keys_recursively(v, keys=keys)
        else:
          keys.append(k)
    return keys

Would there be a better way to do this, or does the above seem like a good approach?

0 Answers
Related