Prism · Composition
Map to a shape
The body of a $map may be a template, so every record of a list comes out in a new shape.
{
users: [
{ id: 'u_1', first: 'Ada', last: 'Lovelace' },
{ id: 'u_2', first: 'Grace', last: 'Hopper' },
{ id: 'u_3', first: 'Linus', last: 'Torvalds' },
],
}{
$map: {
over: { $ref: '$.users' },
as: 'u',
body: {
id: { $get: { from: { $var: 'u' }, path: ['id'] } },
fullName: {
$join: {
sep: ' ',
parts: [
{ $get: { from: { $var: 'u' }, path: ['first'] } },
{ $get: { from: { $var: 'u' }, path: ['last'] } },
],
},
},
},
},
}[
{ id: 'u_1', fullName: 'Ada Lovelace' },
{ id: 'u_2', fullName: 'Grace Hopper' },
{ id: 'u_3', fullName: 'Linus Torvalds' },
]Runs in this page on the installed package. The input and the expected output are defined by the example.