Skip to main content

get

$get

Extracts a value from the input using a dot-separated path (for objects) or a numeric index (for arrays). Does not require the path to be declared as a schema property — use $property when schema-awareness is needed.

Returns undefined if the path does not resolve.

Parameters

  • path (string | number, required): Dot-separated property path or array index.

Example

// Extract a nested property from an object
new Schema('object').transformer({$get: {path: 'database.host'}})
// {database: {host: 'localhost'}} → 'localhost'

// Extract an array element by index
new Schema('array').transformer({$get: {path: 0}})
// ['first', 'second'] → 'first'

// Use as a conditional predicate — only proceed if the path exists
new Schema('object').transformer({
$when: [{$get: {path: 'config.timeout'}}]
})