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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.