Prism · Composition

Pick and rename

A plain object in a config is a template: each of its values is an expression. Reading fields into new names is a template of $refs.

The source
{
  raw: {
    user_id: 'u_42',
    first_name: 'Ada',
    last_name: 'Lovelace',
    created_at: '2024-01-01',
    internal_token: 'sekret',
    legacy_field: 'ignored',
  },
}
The config
{
  id: { $ref: '$.raw.user_id' },
  firstName: { $ref: '$.raw.first_name' },
  lastName: { $ref: '$.raw.last_name' },
  createdAt: { $ref: '$.raw.created_at' },
}
What comes out
{
  id: 'u_42',
  firstName: 'Ada',
  lastName: 'Lovelace',
  createdAt: '2024-01-01',
}
Output matches the expected value

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