Prism · Core

$get

Walks into a value along a list of path segments: keys, indexes, or expressions that evaluate to one. With fallback a missing path gives the fallback; without it the config refuses with E_MISSING_PATH.

The source
{
  catalog: {
    A1: { title: 'Apple', stock: 12 },
    B1: { title: 'Banana', stock: 0 },
  },
  selected: 'B1',
}
The config
{
  title: {
    $get: {
      from: { $ref: '$.catalog' },
      path: [{ $ref: '$.selected' }, 'title'],
    },
  },
  shelf: {
    $get: {
      from: { $ref: '$.catalog' },
      path: [{ $ref: '$.selected' }, 'shelf'],
      fallback: { $const: 'unknown' },
    },
  },
}
What comes out
{ title: 'Banana', shelf: 'unknown' }
Output matches the expected value

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