Need help with recursion problem

I’m trying to create a recursive function to create an array from some schema. The schema is an object that has a “type” key (with options of “array”, “object”, “boolean”, “number” and “string”).

If the type is “array” there can be additional depth. The object would have an “items” key and again the items (as a group) have a “type”.

If the type is “object” then the object would have a “properties” key with each properties key also has a type.

So the schema object describes the shape of the data object but I would like to create a recursive function that creates a default array populated with sensible defaults when dealing with object properties.

Example Schema:

{
  "type": "array",
  "items": {
    "type": "array",
    "items": {
      "type": "object",
      "properties": {
        "testArr": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "testObj": {
          "type": "object"
          "properties": {
            "uglyArr": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "flag": {
                    "type": "boolean"
                  },
                  "age": {
                    "type": "number"
                  },
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Should create:

[
  [
    {
      "testArr": [],
      "testObj": {
        "uglyArr": [
          {
            "flag": false,
            "age": 0,
            "name": ""
          }
        ]
      }
    }
  ]
]

Here are the two methods I’ve written so far:

getValueBasedOnType(obj) {
      if (obj.type === 'boolean') {
        return false;
      }
      if (obj.type === 'number') {
        return 0;
      }
      if (obj.type === 'array') {
        return [];
      }
      if (obj.type === 'object') {
        return this.createObject(obj.properties);
      }
      return '';
    },
    createObject(properties) {
      return keys(properties).reduce((accum, current) => {
        accum[current] = this.getValueBasedOnType(properties[current]);
        return accum;
      }, {});
    },

I can’t quite figure out how to recursively move through the schema object. Any help putting it all together would be appreciated.