Skip to content

pluck

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

{input | pluck:property}
  • input (array): An array of objects to extract values from
  • property (string): The property name to extract from each object
  • 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
{[
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25},
{"name": "Charlie", "age": 35}
] | pluck:"name"}
// Returns: ["Alice", "Bob", "Charlie"]
{vulnerabilities | pluck:"id"}
// Returns array of vulnerability IDs: ["001", "002", "003"]
{findings | pluck:"severity"}
// Returns: ["Critical", "High", "Medium", "Low"]
{[
{"user": {"email": "alice@example.com"}},
{"user": {"email": "bob@example.com"}}
] | pluck:"email"}
// Returns: ["alice@example.com", "bob@example.com"]
{vulnerabilities | pluck:"title" | implode:", "}
// Returns comma-separated list of vulnerability titles
{[
{"name": "Item 1"},
"string item",
{"name": "Item 2"}
] | pluck:"name"}
// Returns: ["Item 1", "string item", "Item 2"]
{{"name": "Single Object"} | pluck:"name"}
// Returns: {"name": "Single Object"} (unchanged)
  • 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
  • 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