%dw 2.0
output application/json  encoding="UTF-8"
---
{
  klantEvents: in0 map ((event, indexOfin0) -> {
    naam: event.apg_name,
    apg_registrationlevel: event.apg_registrationlevel,
    apg_lifeeventid: event.apg_lifeeventid,
    onderwerpen: in0 map ((onderwerp, indexOfOnderwerpen) -> {
      naam: onderwerp.apg_name,
      apg_registrationlevel: onderwerp.apg_registrationlevel,
      apg_lifeeventid: onderwerp.apg_lifeeventid,
      apg_parentevent_referenceto_apg_lifeevent: onderwerp.apg_parentevent_referenceto_apg_lifeevent,
      subonderwerpen: in0 map ((subonderwerp, indexOfSubonderwerpen) -> {
        naam: subonderwerp.apg_name,
        apg_registrationlevel: subonderwerp.apg_registrationlevel,
        apg_lifeeventid: subonderwerp.apg_lifeeventid,
        apg_parentevent_referenceto_apg_lifeevent: subonderwerp.apg_parentevent_referenceto_apg_lifeevent
      }) filter $.apg_registrationlevel == 282770002 filter $.apg_parentevent_referenceto_apg_lifeevent == onderwerp.apg_lifeeventid
    }) filter $.apg_registrationlevel == 282770001 filter $.apg_parentevent_referenceto_apg_lifeevent == event.apg_lifeeventid
  }) filter $.apg_registrationlevel == 282770000
}