graft operators are special expressions that allow you to manipulate and transform your YAML/JSON data during the merge process. They are written in the form (( operator arguments )).
Enhanced Parser Note: graft now uses an enhanced parser by default that supports additional expression operators. See the Expression Operators section for details on boolean logic, comparisons, ternary operator, and more.
New Features:
- Nested Expressions - Operators can now be nested within other operators for powerful compositions
- Environment Variables in References - Use
$VARsyntax in reference paths for dynamic lookups
Transform and manipulate data values:
concat- Concatenate strings and valuesjoin- Join array elements with a delimiterstringify- Convert any value to a stringbase64- Base64 encode a stringbase64-decode- Decode a base64 stringempty- Check if a value is emptynegate- Negate a boolean value
Perform arithmetic and mathematical operations:
+- Addition-- Subtraction*- Multiplication/- Division%- Modulocalc- Complex arithmetic expressionsips- Calculate IP addresses from CIDR ranges
Reference and control data flow:
grab- Reference values from elsewhere in the documentinject- Inject data into specific pathsdefer- Defer operator evaluation for template generationparam- Require parameters to be provided
Manipulate arrays and perform array-specific operations:
- Array Merge Operators:
append- Add items to the end of an arrayprepend- Add items to the beginning of an arrayinsert- Insert items at a specific indexmerge- Merge arrays element by elementinline- Merge array contents inlinereplace- Replace entire arraydelete- Remove items from array
- Array Manipulation:
cartesian-product- Generate cartesian product of arraysshuffle- Randomly shuffle array elementssort- Sort array elements
Load data from external sources:
vault- Retrieve secrets from HashiCorp Vaultvault-try- Try multiple Vault pathsawsparam- Get AWS SSM parametersawssecret- Get AWS Secrets Manager secretsfile- Read local filesload- Load and merge external YAML/JSON files
Utility functions and metadata operations:
keys- Get keys from a mapprune- Remove keys from outputstatic_ips- Generate static IPs for BOSH deployments
7. Expression Operators (Enhanced Parser)
Boolean logic, comparisons, and conditionals:
- Boolean:
&&,||,! - Comparison:
==,!=,<,>,<=,>= - Conditional:
?:(ternary operator)
| Operator | Purpose | Example |
|---|---|---|
grab |
Reference other values | (( grab meta.name )) |
concat |
Join strings | (( concat "Hello " name )) |
vault |
Get secrets | (( vault "secret/db:password" )) |
empty |
Check if empty | (( empty value )) |
calc |
Math expressions | (( calc "2 * (3 + 4)" )) |
join |
Join array | (( join ", " items )) |
Use operators within other operators:
message: (( concat "User: " (grab user.name) " (ID: " (grab user.id) ")" ))Expand environment variables in references:
config: (( grab settings.$ENVIRONMENT.database ))- Arithmetic Operators
- calc - Complex arithmetic expressions
- cartesian-product - Generate cartesian product of arrays
- concat - Concatenate strings and values
- defer - Defer operator evaluation for template generation
- empty - Check if a value is empty
- file - Read local files
- grab - Reference values from elsewhere in the document
- inject - Inject data into specific paths
- ips - Calculate IP addresses from CIDR ranges
- join - Join array elements with a delimiter
- keys - Get keys from a map
- load - Load and merge external YAML/JSON files
- negate - Negate a boolean value
- param - Require parameters to be provided
- prune - Remove keys from output
- shuffle - Randomly shuffle array elements
- sort - Sort array elements
- static_ips - Generate static IPs for BOSH deployments
- stringify - Convert any value to a string
- vault - Retrieve secrets from HashiCorp Vault
- vault-try - Try multiple Vault paths (deprecated, use vault with multiple paths)
- awsparam - Get AWS SSM parameters
- awssecret - Get AWS Secrets Manager secrets
- base64 - Base64 encode a string
- base64-decode - Decode a base64 string
These operators are specific to merging arrays. For more detail see the array merging documentation:
(( append ))- Adds the data to the end of the corresponding array in the root document.(( prepend ))- Inserts the data at the beginning of the corresponding array in the root document.(( insert ))- Inserts the data before or after a specified index, or object.(( merge ))- Merges the data on top of an existing array based on a common key. This requires each element to be an object, all with the common key used for merging.(( inline ))- Merges the data on top of an existing array, based on the indices of the array.(( replace ))- Removes the existing array, and replaces it with the new one.(( delete ))- Deletes data at a specific index, or objects identified by the value of a specified key.
Most graft operators have arguments. There are three basic types to the arguments:
- Literal values (strings/numbers/booleans)
- References (paths defining a datastructure in the root document)
- Environment variables
Arguments can also make use of a logical-or (||) to failover to other values. See our notes on environment variables and default values for more information on environment variables and the logical-or.
Path Syntax Limitation: You cannot use the convenient graft path syntax (path.to.your.property) in case one of the elements (e.g. named entry element) contains a dot as part of the actual key. The dot is in line with the YAML syntax, however it cannot be used since graft uses it as a separator internally. This also applies to operators, where it is not immediately obvious that a path is used like with the (( prune )) operator. As a workaround, depending on the actual use-case, it is often possible to replace the graft operator with a equivalent [go-patch] operator file.
- Examples Directory - Practical examples for each operator
- Quick Reference - One-page operator reference
- Expression Operators - Boolean logic and comparisons
- Array Operations - Detailed array manipulation
- External Data - Working with external data sources