logo
Report templatesFunctions

pluck

Extract a specific property from an array of objects

Usage

The pluck function extracts a specific property from each object in an array, returning a new array containing only those values.

Syntax

{input | pluck:property}

Parameters

  • input (array): An array of objects to extract values from
  • property (string): The property name to extract from each object

Returns

  • Array containing the specified property value from each object
  • Returns input unchanged if not an array or if input is null/undefined
  • For non-object array items, returns the item unchanged

Examples

Extract names from users

{[
  {"name": "Alice", "age": 30},
  {"name": "Bob", "age": 25},
  {"name": "Charlie", "age": 35}
] | pluck:"name"}
// Returns: ["Alice", "Bob", "Charlie"]

Extract IDs from vulnerabilities

{vulnerabilities | pluck:"id"}
// Returns array of vulnerability IDs: ["001", "002", "003"]

Extract severity levels

{findings | pluck:"severity"}
// Returns: ["Critical", "High", "Medium", "Low"]

Extract nested property

{[
  {"user": {"email": "alice@example.com"}},
  {"user": {"email": "bob@example.com"}}
] | pluck:"email"}
// Returns: ["alice@example.com", "bob@example.com"]

Chain with other filters

{vulnerabilities | pluck:"title" | implode:", "}
// Returns comma-separated list of vulnerability titles

Mixed array types

{[
  {"name": "Item 1"},
  "string item",
  {"name": "Item 2"}
] | pluck:"name"}
// Returns: ["Item 1", "string item", "Item 2"]

Non-array input

{{"name": "Single Object"} | pluck:"name"}
// Returns: {"name": "Single Object"} (unchanged)

Use Cases

  • Extracting specific fields for display in lists
  • Creating arrays of IDs for further processing
  • Simplifying complex data structures in reports
  • Preparing data for charts (e.g., extracting labels or values)
  • Building dropdown options from object arrays
  • Combining with implode to create formatted lists

Notes

  • Returns input unchanged if input is null or undefined
  • Non-array inputs are returned as-is
  • If an array item is not an object, it's included unchanged in the output
  • Useful for data transformation in report templates
  • Often combined with other filters like implode or joinWith