title: How do I access the $ref in the JSON recursively as to complete the whole JSON?
body: <p>I have this schema, which has <code>$ref</code> in it. I need to recursively (assuming there are no infinite cycles) fill in references. That is, wherever <code>$ref</code> is present, the whole object is replaced with what it points.</p>
  
  <p>Note, I can't use any libraries and need to write the Class/function on my own. I did see <a href="https://github.com/gazpachoking/jsonref/blob/master/jsonref.py" rel="nofollow noreferrer">jsonref</a> but was unable to understand the LazyLoad and the callbacks.</p>
  
  <p>Could it be done in a simpler way? I've been trying to do this for days.</p>
  
  <pre><code>{
    "definitions": {
      "pet": {
        "type": "object",
        "properties": {
          "name":  { "type": "string" },
          "breed": { "type": "string" },
          "age":  { "type": "string" }
        },
        "required": ["name", "breed", "age"]
      }
    },
    "type": "object",
    "properties": {
      "cat": { "$ref": "#/definitions/pet" },
      "dog": { "$ref": "#/definitions/pet" }
    }
  }
  </code></pre>
  
  <p>becomes, </p>
  
  <pre><code>{
    "definitions": {
      "pet": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "breed": {
            "type": "string"
          },
          "age": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "breed",
          "age"
        ]
      }
    },
    "type": "object",
    "properties": {
      "cat": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "breed": {
            "type": "string"
          },
          "age": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "breed",
          "age"
        ]
      },
      "dog": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "breed": {
            "type": "string"
          },
          "age": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "breed",
          "age"
        ]
      }
    }
  }
  </code></pre>
  
  <p>This is the JSON I'm trying to solve, thanks.</p>
  
  <pre><code>{
    "$id": "https://example.com/nested-schema.json",
    "title": "nested-schema",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "required": [
      "Music",
      "MusicID",
      "Composer"
    ],
    "properties": {
      "MusicID": {
        "type": "string",
        "minLength": 0,
        "maxLength": 0
      },
      "Music": {
        "$ref": "#/definitions/Music"
      },
      "Composer": {
        "type": "integer",
        "minimum": 0,
        "maximum": 0
      }
    },
    "definitions": {
      "Music": {
        "type": "object",
        "required": [
          "Date"
        ],
        "properties": {
          "Date": {
            "type": "string",
            "format": "date"
          },
          "Artist": {
            "$ref": "#/definitions/AlbumInformation"
          }
        }
      },
      "AlbumInformation": {
        "type": "object",
        "required": [
          "Name"
        ],
        "properties": {
          "Name": {
            "type": "string",
            "minLength": 5
          }
        }
      }
    },
    "description": "nested-schema"
  }
  </code></pre>
  
  <p>Help will be deeply appreciated, thanks.</p>
  
  <p>Some code that I have been trying:</p>
  
  <pre><code>@classmethod
  def replace_refs(cls, obj, _recursive=False, **kwargs):
      kwargs["_recursive"] = True
      path = list(kwargs.pop("_path", ()))
      if isinstance(obj, Mapping):
          for k, v in obj.items():
              if isinstance(v, dict):
                  if '$ref' in v:
                      import pdb
                      print(k, v)
              cls.replace_refs(v)
      return obj
  </code></pre>