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.

The source
{
  users: [
    { id: 'u_1', first: 'Ada', last: 'Lovelace' },
    { id: 'u_2', first: 'Grace', last: 'Hopper' },
    { id: 'u_3', first: 'Linus', last: 'Torvalds' },
  ],
}
The config
{
  $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'] } },
          ],
        },
      },
    },
  },
}
What comes out
[
  { id: 'u_1', fullName: 'Ada Lovelace' },
  { id: 'u_2', fullName: 'Grace Hopper' },
  { id: 'u_3', fullName: 'Linus Torvalds' },
]
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.