Expression Syntax
Expressions are the language for transforming data in TinySystems. They allow you to select, modify, and combine data as it flows between nodes.
Basic Syntax
All expressions are wrapped in double curly braces:
text
{{expression}}Simple Examples
yaml
# Reference a value
name: "{{$.userName}}"
# Math operation
total: {{$.price * $.quantity}}
# String concatenation
greeting: "Hello, {{$.name}}!"The Root Reference: $
The $ symbol represents the root of the incoming data:
json
// Incoming data
{
"user": {
"name": "Alice",
"email": "alice@example.com"
},
"items": [1, 2, 3]
}yaml
# Expression examples
userName: "{{$.user.name}}" # "Alice"
email: "{{$.user.email}}" # "alice@example.com"
allData: {{$}} # The entire objectProperty Access
Dot Notation
Access nested properties with dots:
yaml
# $.property.nested.deep
city: "{{$.address.city}}"
zip: "{{$.address.postalCode}}"Bracket Notation
Use brackets for special characters or dynamic keys:
yaml
# $.property["key with spaces"]
value: "{{$.data['my field']}}"
# Dynamic key access
fieldValue: "{{$.data[$.fieldName]}}"Array Access
By Index
Access array elements by position:
yaml
# First element (0-indexed)
first: "{{$.items[0]}}"
# Third element
third: "{{$.items[2]}}"
# Last element
last: "{{$.items[-1]}}"
# Second to last
secondLast: "{{$.items[-2]}}"Array Length
Get the number of elements:
yaml
count: {{$.items.length}}
hasItems: {{$.items.length > 0}}Expression Types
Pure Expressions
Without quotes, expressions preserve their type:
yaml
# Returns number
count: {{$.count}}
# Returns boolean
active: {{$.isActive}}
# Returns object
user: {{$.userData}}
# Returns array
items: {{$.list}}String Interpolation
With quotes, the result is always a string:
yaml
# Returns string "42"
countStr: "{{$.count}}"
# Returns string "true"
activeStr: "{{$.isActive}}"
# Interpolated string
message: "You have {{$.count}} items"Mixed Content
Combine static text with expressions:
yaml
# Multiple expressions in one string
summary: "{{$.firstName}} {{$.lastName}} ({{$.age}} years old)"
# Expressions with formatting
email: "{{$.name}}@{{$.domain}}"
url: "https://api.example.com/users/{{$.userId}}"Operators
Arithmetic
yaml
sum: {{$.a + $.b}}
difference: {{$.a - $.b}}
product: {{$.a * $.b}}
quotient: {{$.a / $.b}}
remainder: {{$.a % $.b}}Comparison
yaml
equal: {{$.a == $.b}}
notEqual: {{$.a != $.b}}
greater: {{$.a > $.b}}
less: {{$.a < $.b}}
greaterOrEqual: {{$.a >= $.b}}
lessOrEqual: {{$.a <= $.b}}Logical
yaml
and: {{$.a && $.b}}
or: {{$.a || $.b}}
not: {{!$.a}}Ternary (Conditional)
yaml
result: "{{$.active ? 'enabled' : 'disabled'}}"
status: {{$.count > 0 ? $.items : []}}Special Expressions
Default Values
Use || to provide fallbacks:
yaml
# Use "Unknown" if name is null/empty
name: "{{$.name || 'Unknown'}}"
# Use 0 if count is undefined
count: {{$.count || 0}}
# Chain defaults
value: "{{$.primary || $.secondary || $.fallback}}"Null Checks
Check for existence:
yaml
hasUser: {{$.user != null}}
isEmpty: {{$.items.length == 0}}String in Expressions
Strings within expressions use single quotes:
yaml
# Compare with string
isAdmin: {{$.role == 'admin'}}
# String literal
default: "{{$.name || 'Anonymous'}}"Object Construction
Build new objects:
yaml
# Simple object
user:
id: "{{$.userId}}"
name: "{{$.userName}}"
# Nested structure
response:
success: true
data:
user: {{$.user}}
timestamp: "{{now()}}"Array Expressions
Access Elements
yaml
# Specific elements
first: {{$.items[0]}}
second: {{$.items[1]}}
# From end
last: {{$.items[-1]}}Array Properties
yaml
length: {{$.items.length}}
isEmpty: {{$.items.length == 0}}Function Calls
Call built-in functions:
yaml
# Current timestamp
timestamp: "{{now()}}"
# Format date
formatted: "{{RFC3339($.date)}}"
# Type conversion
numericString: "{{string($.count)}}"See Operators and Functions for the complete list.
Escaping
Literal Curly Braces
To output literal {{:
yaml
# Use escaped notation
template: "\\{\\{not an expression\\}\\}"Quotes in Strings
yaml
# Single quotes inside double quotes
message: "He said 'hello'"
# Escaped quotes
quote: "She said \"hi\""Common Patterns
Conditional Mapping
yaml
# Map based on condition
status: "{{$.value > 100 ? 'high' : 'normal'}}"
# Complex condition
category: "{{$.age < 18 ? 'minor' : ($.age < 65 ? 'adult' : 'senior')}}"Safe Navigation
yaml
# Use default for potentially missing fields
email: "{{$.user.email || 'not provided'}}"
# Check before access
userName: "{{$.user != null ? $.user.name : 'Guest'}}"String Formatting
yaml
# Build URL
url: "https://api.example.com/{{$.version}}/users/{{$.userId}}"
# Format message
notification: "User {{$.userName}} ({{$.userId}}) logged in at {{now()}}"Debugging Expressions
Common Errors
| Error | Cause | Fix |
|---|---|---|
| "undefined" | Path doesn't exist | Check data structure |
| Type mismatch | Wrong type returned | Use/remove quotes appropriately |
| Syntax error | Invalid expression | Check brackets/quotes |
Testing Tips
- Use Debug node to see actual data
- Start with simple
{{$}}to see all data - Build expressions incrementally
- Check types match expectations
Next Steps
- JSONPath Reference - Path syntax details
- Operators and Functions - Available operations
- Expression Examples - Real-world examples