title: Using Typescript Interface with a Recursive JSON
body: <p>I am trying to adapt a product's ontology with its properties using JSON. The below mentioned JSON structure is what I am thinking about.</p>
  
  <blockquote>
    <p>Each Product (Concept) has two types of properties:
      1. Data Properties 2. Object Properties</p>
  </blockquote>
  
  <p>Typical Definitions for these properties when using Protege is as follows<sup><a href="https://stackoverflow.com/questions/17724983/how-can-i-recognize-object-properties-vs-datatype-properties#17729832">SO Thread</a></sup>:</p>
  
  <blockquote>
    <p>In Protégé there are are different tabs for creating Object Properties and Datatype Properties. If a property should relate individuals to individuals, then it needs to be an object property, and if it relates individuals to literals, then it needs to be a datatype property.</p>
  </blockquote>
  
  <p>I think of every property to have the following attributes:</p>
  
  <pre><code>name: string
  url: string
  type: dataprop or objprop
  objPropSource: available only for Objproperties
  </code></pre>
  
  <p>I have drawn up a small recursive JSON as below:</p>
  
  <pre><code>{
    "name": "chair",
    "url": "http://namespace.org#chair",
    "type": "main",
    "properties": [
      {
        "name": "height",
        "url": "http://namespace.org#height",
        "type": "dataprop"
      },
      {
        "name": "width",
        "url": "http://namespace.org#width",
        "type": "dataprop"
      },
      {
        "name": "horizontalsurface",
        "url": "http://namespace.org#horizontalsurface",
        "type": "objprop",
        "objPropSource": "http://namespace.org#hasHorizontalSurface",
        "properties": [
          {
            "name": "Legislation",
            "url": "http://namespace.org#legislation",
            "type": "objprop",
            "objPropSource": "http://namespace.org#compliesWithLegislation",
            "properties": [
              {
                "name": "hasLegislationName",
                "url": "http://namespace.org#hasLegislationName",
                "type": "dataprop"
              }
              ]
          }
          ]
      },
      {
        "name": "legislation",
        "url": "http://namespace.org#legislation",
        "type": "objprop",
        "objPropSource": "http://namespace.org#compliesWithLegistion",
        "properties": [
          {
            "name": "hasLegislationName",
            "url": "http://namespace.org#hasLegislationName",
            "type": "dataprop"
          }
          ]
      }
    ]
  }
  </code></pre>
  
  <p>In a way structure provides a Binary Tree for a chair which has <code>height</code>, <code>width</code> etc. as <em>dataproperties</em> and <code>horizontalsurface</code> and <code>legislation</code> as objectproperties</p>
  
  <h2>JSON to Interface in Typescript</h2>
  
  <p>I used the <a href="http://www.jsontots.com/" rel="nofollow noreferrer">JSON to TS Online Converter</a> to see how will the JSON be converted to Typescript Interfaces and the outcome is following:</p>
  
  <pre><code>interface RootObject {
    name: string;
    url: string;
    type: string;
    properties: Property3[];
  }
  
  interface Property3 {
    name: string;
    url: string;
    type: string;
    objPropSource?: string;
    properties?: Property2[];
  }
  
  interface Property2 {
    name: string;
    url: string;
    type: string;
    objPropSource?: string;
    properties?: Property[];
  }
  
  interface Property {
    name: string;
    url: string;
    type: string;
  }
  </code></pre>
  
  <h3>Inference</h3>
  
  <p>I infer that the aprroach for using Interfaces from Recursive JSON is not scalable since such an Ontology of a Product can scale upto 1000's of properties and properties within properties. As above mentioned example show that for every Property within a parent property would keep creating interfaces.</p>
  
  <h3>Expectation</h3>
  
  <p>Should I expect to use Typescript Interfaces with such JSON structure or should to stick to creating a Class and then following the conventional method of creating a Binary Tree viz.</p>
  
  <pre><code>export class leaf {
    name: string;
    url: string;
    type: string;
    children: leaf[] = [];
  }
  </code></pre>
  
  <p>and then writing a recursion till the complete structure is parsed?</p>
  
  <h1>TL;DR</h1>
  
  <blockquote>
    <p>Can Typescript interfaces be used for Large Recursive JSON Structures?</p>
  </blockquote>