HomeGuidesRecipesAPI
HomeGuidesAPILog In

Hierarchical Data

A hierarchical datasource is a data model in which data is stored in the form of records and organized into a tree-like structure, or parent-child structure, in which one parent node can have many child nodes connected through links.

Image from EDUCBA

The hierarchical database model requires that each child record has only one parent, whereas each parent record can have one or more child records, usually in the form of an array or collection of objects.

JSON and XML files often include hierarchical data, in SmartIQ you'll get one of those if you are using one of the following Data Sources:

  • JSON
  • XML
  • Web Service (SOAP)
  • REST

Here are two examples of hierarchical data:

<?xml version="1.0" encoding="utf-8"?>
<students>
  <student id="0001">
    <name>Justin</name>
    <lastName>Example</lastName>
    <subjects>
      <subject>
        <name>Science</name>
      </subject>
      <subject>
        <name>Nature History</name>
      </subject>
      <subject>
        <name>Biology</name>
      </subject>
    </subjects>
  </student>
</students>
{
  "students": {
    "student": {
      "-id": "0001",
      "name": "Justin",
      "lastName": "Example",
      "subjects": {
        "subject": [
          { "name": "Science" },
          { "name": "Nature History" },
          { "name": "Biology" }
        ]
      }
    }
  }
}

Level 1

  • name
  • lastName

Level 2

  • subject/name

Configure a hierarchical datasource

  1. Create the hierarchical datasource in Manage > Data Connections
  2. Add a schema.
  3. If the datasource is not online, you will need to add some default data.
  4. Check the data source is showing the hierarchical display fields you require. All the fields will be shown for all child data sets, not just the top level.
  5. In Design, add your Data Connection as a data question (top-level hierarchical questions will often be invisible and set to a Single Row selection as they are simply containers for the child data sets). In this example, the top level is just a container for the $person[] array.
  6. Add the child data references. Scroll down the list of Data Connections to find Data Question then choose the relevant child data set from the list of data objects. From this data question you will be able to access the display fields at this level eg: $person[].name, $person[].eMail, $person[].dateOfBirth
  7. Once you have a child set as a Data Question, you can then access the child data sets inside that by the same method. So you can set up a Data Question to access the $person[].assets[] to view the data in the fields $person[].assets[].description, $person[].assets[].type and $person[].assets[].value for the $person[] selected in the parent question.

🚧

Note:

For hierarchical REST datasources, the schema must be supplied in Swagger format.

An example of a project that uses a JSON hierarchical data connection can be found here: