0

I've dataset pulled from a linked data platform. The dataset looks like this:

label relationClass
Organization Department
Department Employee

I want to create a JSON Schema based on this data where the hierarchy between objects is nested.

The decomposition of the hierarchy look something like this:

Organization

  • Department
    • Employee

Eventually the parsing should result in a JSON Schema looking like this:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "organization": {
      "type": "object",
      "properties": {
        "department": {
          "type": "object",
          "properties": {
            "employee": {
              "type": "object"
            }
          }
        }
      }
    }
  }
}

Can someone help out with the most efficient way to achieve this?

Sef
  • 85
  • 7

1 Answers1

0

It looks like a classical tree structure. For optimal performance you'd go over it once and build a tree/directed graph from it, then recursively traverse in preorder to create all the children of the nodes as object.

Searching for 'build tree from list of pairs' yielded the following SO question with a working answer: Given a flat list of (parent,child), create a hierarchical dictionary tree

Lukas Schmid
  • 1,895
  • 1
  • 6
  • 18
  • It worked out to throw this in a tree structure. However, how do I parse this to a JSON Schema format? Meaning the objects and properties, objects and properties and so on? – Sef Jun 01 '22 at 12:58