Skip to content

Map arrays of objects

To map every element of an array, scope with source and pair inside each:

/people:
source: /contributors
each:
/name: /fullName
/role: { source: /role, default: author }
{
"contributors": [
{ "fullName": "Grace Hopper", "role": "editor" },
{ "fullName": "Emmy Noether" }
]
}

becomes:

{
"people": [
{ "name": "Grace Hopper", "role": "editor" },
{ "name": "Emmy Noether", "role": "author" }
]
}

Each element maps against a fresh target. Pointers inside each read from the element.

To read one element, point into it by index:

/lead: /contributors/0/fullName

To fall back across fields, use an array descriptor. The first defined result wins, per element:

/people:
source: /contributors
each:
/name: ['/nickname', '/fullName']