Hi, I'm having a few issues getting an expression which can obtain data from

Hi, I'm having a few issues getting an expression which can obtain data from a 2nd tier of nested objects.
Essentially I have a collection of "Parents" where the data for children can be described using ad-hoc data structure as:

= {
{
ParentName: "Amanda",
children: {
{
Child: {
ChildName: "Emma"
}
},
{
Child: {
ChildName: "Abi"
}
}
}
},
{
ParentName: "Kyle",
children: {
{
Child: {
ChildName: "Ethan"
}
}
}
}
}

What I'm after is an array of text values for all the ChildNames - but I can't seem to make use of the apply, merge or union functions to achieve this. Any Ideas?...

OriginalPostID-124332

OriginalPostID-124332

  Discussion posts and replies are publicly visible

Parents
  • To do that you will need two rules. The inner rule will put out the child names from each parent and the outer rule will apply that inner rule to each parent. It will look like this:

    ***PARENT RULE***

    with(
    local!data: {
    {
    ParentName: "Amanda",
    children: {
    {
    Child: {
    ChildName: "Emma"
    }
    },
    {
    Child: {
    ChildName: "Abi"
    }
    }
    }
    },
    {
    ParentName: "Kyle",
    children: {
    {
    Child: {
    ChildName: "Ethan"
    }
    }
    }
    }
    },
    apply(
    rule!Child_Rule,
    enumerate(length(local!data)) + 1,
    local!data
    )
    )


    ***CHILD RULE***

    Inputs:

    index (int)
    data (any type)

    index(index(index(index(ri!data, ri!index,""), "children", ""), "Child", ""), "ChildName")
Reply
  • To do that you will need two rules. The inner rule will put out the child names from each parent and the outer rule will apply that inner rule to each parent. It will look like this:

    ***PARENT RULE***

    with(
    local!data: {
    {
    ParentName: "Amanda",
    children: {
    {
    Child: {
    ChildName: "Emma"
    }
    },
    {
    Child: {
    ChildName: "Abi"
    }
    }
    }
    },
    {
    ParentName: "Kyle",
    children: {
    {
    Child: {
    ChildName: "Ethan"
    }
    }
    }
    }
    },
    apply(
    rule!Child_Rule,
    enumerate(length(local!data)) + 1,
    local!data
    )
    )


    ***CHILD RULE***

    Inputs:

    index (int)
    data (any type)

    index(index(index(index(ri!data, ri!index,""), "children", ""), "Child", ""), "ChildName")
Children
No Data