Path Iterator

Use the path iterator when you want to handle an array of objects; for example, this JSON shows some scores that were applied during tagging:

{
    "interaction": {
        "id": 12345,
        "tag_tree": {
            "skills": {
                "programming": {
                    "php": 100,
                    "nodejs": 76,
                    "java": 50
                },
                "databases": {
                    "mysql": 100,
                    "oracle": 20
                }
            }
        }
    }
}

Here, the skills node in the JSON tree contains two objects, both of which contains scores held as integers.

The path iterator processes this kind of information as key-value pairs. The key is the path that we took through the JSON to find the value.

ID PATH VAL
12345 skills.programming.php 100
12345 skills.programming.nodejs 76
12345 skills.programming.java 50
12345 skills.databases.mysql 100
12345 skills.databases.oracle 20

The .INI definition to build this table is:

[TAGS :iter = path_iterator(tag_tree)]
ID = interaction.id
PATH = :iter._path
VAL = :iter._value

It works in a similar way with strings:

{
    "interaction": {
        "tag_tree": {
            "skills": {
                "programming": [
                    "php",
                    "nodejs",
                    "java"
                ],
                "databases": [
                    "mysql",
                    "oracle"
                ]
            }
        }
    }
}

This .INI file:

[TAGS :iter = path_iterator(tag_tree)]
ID = interaction.id
PATH = :iter._path
VAL = :iter._value

Generates this table:

ID PATH VAL
12345 skills.programming ["php","nodejs","java"]
12345 skills.databases ["mysql","oracle"]

PATH and VAL are constructed from the data in the interaction. The underscores in _path and _value in the INI file indicates that the data is built on the fly rather than simply pulled directly from the interaction.