Syntax Reference
Complete syntax reference for YAML Toolkit for Obsidian rules.
Rule Structure
A rule has two parts entered in separate fields:
Condition field: What to match
<condition>Action field: What to do
<operation> [arguments]Important: The plugin automatically evaluates conditions and executes actions. Just enter the condition and action directly.
Action Syntax: Hybrid Grammar
Two syntax styles based on target type:
SCALAR operations (no FOR prefix):
SET field value # Set/create field
DELETE field # Delete field
RENAME field TO newname # Rename field
INCREMENT field number # Add to number
DECREMENT field number # Subtract from numberCOLLECTION operations (FOR prefix required):
FOR array APPEND value # Add to end
FOR array PREPEND value # Add to start
FOR array INSERT value AT index # Insert at position
FOR array WHERE condition SET field value # Update matching items
FOR array SORT BY field # Sort array
FOR object MERGE data # Merge objectsKey principle: SCALARS operate on single fields directly. COLLECTIONS operate on arrays/objects and need FOR to specify the target.
Conditions
Comparison Operators
=- Equals!=- Not equals>- Greater than<- Less than>=- Greater than or equal<=- Less than or equal
Condition examples:
status = "active"
count > 10
date >= "2025-01-01"Logical Operators
AND- Both conditions must be trueOR- Either condition can be trueNOT- Negates a condition
Examples:
tags contains "project" AND status != "archived"
priority = "high" OR deadline < "{{today}}"
NOT HAS completed_dateSpecial Operators
contains- Check if array contains valueHAS- Check if field existsIN- Check if value is in list
Examples:
tags contains "important"
HAS custom_field
status IN ["draft", "review", "published"]Advanced Operators
Powerful Features
These advanced condition operators provide precise querying and validation capabilities for your YAML frontmatter.
.length - Count Items or Characters
field.length- Get count of array items, string characters, or object keys- Works with:
=,!=,>,<,>=,<=
Examples:
tags.length > 0 # Has tags
title.length < 50 # Short title
metadata.length >= 5 # Many metadata fieldsempty / !empty - Check for Empty Values
field empty- Field is empty array[], empty string"", or empty object{}field !empty- Field has content
Examples:
tags empty # Empty array
content !empty # Has content
tags exists AND tags !empty # Has tags and they're populatedNote: Missing fields and null values return false for empty check.
Type Checking
Validate field data types:
field :string- Field is a stringfield :number- Field is a numberfield :boolean- Field is boolean (true/false)field :array- Field is an arrayfield :object- Field is an objectfield :null- Field is nullfield !:type- Field is NOT of type (negated)
Examples:
status :string # Status is text
priority :number # Priority is numeric
tags :array # Tags is an array
tags !:string # Tags is NOT a stringANY / ALL - Array Quantifiers
Check conditions across array items:
ANY - At least one item matches:
ANY <array> WHERE <condition>ALL - Every item matches:
ALL <array> WHERE <condition>Examples:
ANY projects WHERE status = "active"
ALL tasks WHERE assignee exists
ANY projects WHERE ANY tasks WHERE status = "pending" # NestedAction Operations
SET - Create or Update Fields
Purpose: Set a field value (creates if missing, updates if exists)
Syntax:
SET <field> <value>Examples:
SET status "active"
SET priority 1
SET tags ["project", "active"]
SET metadata {author: "John", version: 2}Use when: You need to ensure a field has a specific value regardless of its current state.
FOR ... APPEND - Add to End of Array
Purpose: Add item to end of array (with de-duplication)
Syntax:
FOR <array> APPEND <value>Examples:
FOR tags APPEND "reviewed"
FOR categories APPEND "work"Use when: Building lists incrementally, adding to the end without duplicates.
FOR ... PREPEND - Add to Start of Array
Purpose: Add item to start of array (with de-duplication)
Syntax:
FOR <array> PREPEND <value>Examples:
FOR tags PREPEND "urgent"
FOR categories PREPEND "important"Use when: Adding priority items to the beginning of lists.
FOR ... REMOVE - Delete from Lists (Conditional)
Purpose: Remove specific items matching a condition
Syntax:
FOR <array> WHERE <condition> REMOVEExamples:
FOR tags WHERE $ = "draft" REMOVE
FOR items WHERE priority < 3 REMOVENote: REMOVE requires a WHERE clause to specify what to remove.
FOR ... REMOVE_ALL - Delete All Occurrences
Purpose: Remove all instances of a specific value
Syntax:
FOR <array> REMOVE_ALL <value>Examples:
FOR tags REMOVE_ALL "draft"
FOR categories REMOVE_ALL "archived"Use when: Removing a specific value regardless of how many times it appears.
FOR ... REMOVE_ANY - Delete Multiple Values
Purpose: Remove all instances of any value in a list
Syntax:
FOR <array> REMOVE_ANY [<value1>, <value2>, ...]Examples:
FOR tags REMOVE_ANY ["draft", "wip", "temp"]
FOR categories REMOVE_ANY ["old", "deprecated"]Use when: Cleaning up multiple unwanted values at once.
DELETE - Remove Entire Field
Purpose: Remove field completely from front matter
Syntax:
DELETE <field>Examples:
DELETE old_field
DELETE temp_statusUse when: Cleaning up obsolete or temporary fields.
RENAME - Rename Field
Purpose: Rename a field while preserving its value across all documents
Syntax:
RENAME <old_field> TO <new_field>Examples:
RENAME author TO creator
RENAME due_date TO deadline
RENAME tags TO categoriesWhy it's atomic: Cannot be replicated with DELETE + SET because each document has unique values. RENAME preserves all values:
Before (different values in different docs):
# Doc 1: author: "Alice"
# Doc 2: author: "Bob"
# Doc 3: author: "Charlie"After RENAME author TO creator:
# Doc 1: creator: "Alice"
# Doc 2: creator: "Bob"
# Doc 3: creator: "Charlie"Use when: Standardizing field names across your vault while preserving all unique values.
REPLACE - Pattern Substitution
Purpose: Find and replace patterns in string values using regex
Syntax:
REPLACE <field> /<regex>/ <replacement>Examples:
REPLACE author /^Dr\.?\s+// ""
REPLACE title /\s+/ "_"
REPLACE content /TODO: // "✓ "Use when: Transforming string content with pattern matching.
INCREMENT - Add to Numeric Field
Purpose: Add to numeric field (positive or negative)
Syntax:
INCREMENT <field> <amount>Examples:
INCREMENT view_count 1
INCREMENT priority -1
INCREMENT score 10Use when: Tracking counters, scores, or numeric values that change over time.
DECREMENT - Subtract from Numeric Field
Purpose: Subtract from numeric field
Syntax:
DECREMENT <field> <amount>Examples:
DECREMENT remaining_tasks 1
DECREMENT credits 5
DECREMENT attempts 1Use when: Counting down values or tracking decreases.
FOR ... INSERT - Insert at Position
Purpose: Insert value at specific position in arrays or strings
Syntax:
FOR <field> INSERT <value> AT <index>Special indices:
0- Insert at start (beginning)-1- Insert at end- Positive numbers - Insert at that position
- Negative numbers - Count from end
Examples:
# Arrays
FOR tags INSERT "urgent" AT 0 # Insert at start
FOR tags INSERT "archived" AT -1 # Insert at end
FOR history INSERT "checkpoint" AT 5 # Insert at position 5
# Strings (concatenation)
FOR title INSERT "DRAFT: " AT 0 # Prepend text
FOR notes INSERT "\n---\n" AT -1 # Append textUse when: Adding items to arrays or concatenating strings at any position.
Array of Objects Operations
Special operations for structured arrays like task lists.
FOR ... WHERE ... SET - Update Items
Purpose: Update fields in objects matching a condition
Syntax:
FOR <array> WHERE <condition> SET <field> <value> [, <field> <value>]Examples:
FOR tasks WHERE status = "pending" SET status "active", started "{{today}}"
FOR items WHERE priority < 3 SET priority 5
FOR entries WHERE type = "draft" SET type "review", reviewed trueUse when: Updating specific objects within arrays based on their properties.
FOR ... WHERE ... MOVE - Reorder Items
Purpose: Move items matching condition within array
Syntax:
FOR <array> WHERE <condition> MOVE TO <position>Positions: START, END, AFTER <condition>, BEFORE <condition>
Examples:
FOR tasks WHERE priority > 7 MOVE TO START
FOR items WHERE status = "done" MOVE TO END
FOR tasks WHERE urgent = true MOVE TO AFTER name = "Planning"Use when: Prioritizing or organizing items without full sorting.
FOR ... SORT - Sort Arrays
Purpose: Sort array in ascending or descending order
Syntax:
FOR <array> SORT [<order>]
FOR <array> SORT BY <field> [<order>]Orders: ASC (ascending), DESC (descending). Default is ASC.
Examples:
FOR tags SORT ASC
FOR priorities SORT DESC
FOR tasks SORT BY priority DESC
FOR entries SORT BY date ASCUse when: Organizing simple arrays or object arrays by field values.
FOR ... MOVE - Move by Index
Purpose: Move item from one index to another
Syntax:
FOR <array> MOVE FROM <index> TO <index>Examples:
FOR tags MOVE FROM 0 TO 5
FOR history MOVE FROM -1 TO 0Use when: Manual reordering by position.
FOR ... DEDUPLICATE - Remove Duplicates
Purpose: Remove duplicate values from array
Syntax:
FOR <array> DEDUPLICATEExamples:
FOR tags DEDUPLICATE
FOR categories DEDUPLICATEUse when: Cleaning up arrays with duplicate values.
Object Operations
FOR ... MERGE - Deep Merge Objects
Purpose: Deep merge objects (preserves existing nested fields)
Syntax:
FOR <object> MERGE {<key>: <value>, ...}Examples:
FOR metadata MERGE {author: "John", version: 2}
FOR config MERGE {theme: "dark", showIcons: true}Use when: Adding or updating nested object fields while preserving others.
FOR ... MERGE_OVERWRITE - Shallow Merge Objects
Purpose: Shallow merge objects (overwrites all fields)
Syntax:
FOR <object> MERGE_OVERWRITE {<key>: <value>, ...}Examples:
FOR metadata MERGE_OVERWRITE {author: "Jane", version: 3}
FOR settings MERGE_OVERWRITE {mode: "advanced"}Use when: Replacing entire object contents.
Special Values
Template Variables
Template variables are evaluated at runtime and inserted into action values.
- Current timestamp (ISO 8601)- Today's date (YYYY-MM-DD)
Examples:
SET created_date "{{now}}"
SET updated "{{today}}"
SET reviewed_on "{{today}}"Data Types
- Strings:
"text"(use quotes) - Numbers:
42,3.14 - Booleans:
true,false - Arrays:
["item1", "item2"] - Objects:
{key: "value", nested: {foo: "bar"}} - Dates:
"2025-01-01"
Path Syntax & Array Access
Accessing Nested Data
Use dot notation and brackets to access nested structures:
field # Top-level field
object.property # Object property
array[0] # Array by index
object.nested.deep # Multi-level nesting
array[0].property # Object within arrayDeep nesting examples:
# Multi-level object paths
metadata.author.profile.name
config.server.database.connection.host
# Nested arrays within objects
projects[0].phases[1].tasks[2].status
teams[0].members[5].skills[0]
# Mixed nesting patterns
data.servers[0].endpoints[0].methods[1]
workflow.steps[0].substeps[2].validation.rules[0]Real-world access patterns:
# Check nested status
Condition: projects[0].milestones[2].completed = true
# Update deep nested value
Action: SET config.api.endpoints[0].rateLimit 5000
# Access nested array property
Condition: teams[1].members[-1].role = "lead"Negative Indexing
Access array items from the end using negative indices:
Syntax:
array[-1]- Last itemarray[-2]- Second-to-last itemarray[-n]- Nth item from end
Examples:
Check last task status:
Condition: tasks[-1].status = "done"Update second-to-last entry:
Action: FOR history[-2] SET reviewed trueInsert before last item:
Action: FOR tags INSERT "archived" AT -2Access nested array from end:
Condition: projects[0].tasks[-1].priority > 7
Action: SET projects[-1].status "completed"Use cases:
- Check most recent item in log/history arrays
- Update last entry without knowing array length
- Insert items relative to end of array
- Access latest task, note, or record
Error Handling & Edge Cases
Understanding how the plugin handles different data states.
Missing Fields
Path doesn't exist:
Condition: nonexistent.field = "value"
Result: Condition evaluates to false, file skippedAction on missing field:
Action: FOR tags APPEND "new-tag"
# If tags doesn't exist → Creates array: ["new-tag"]
# If tags exists → Appends to existing arrayNull vs Empty vs Missing
Field doesn't exist:
# Field not present in frontmatterfield empty→ false (can't be empty if doesn't exist)field exists→ falseHAS field→ falseFOR field APPEND "x"→ Creates new array:["x"]
Null value:
field: nullfield empty→ false (null ≠ empty)field :null→ truefield exists→ trueFOR field APPEND "x"→ Replaces with array:["x"]
Empty array:
field: []field empty→ truefield.length = 0→ truefield exists→ trueFOR field APPEND "x"→ Result:["x"]
Empty string:
field: ""field empty→ truefield.length = 0→ truefield = ""→ true
Empty object:
field: {}field empty→ truefield.length = 0→ truefield exists→ true
Type Mismatches
Increment on non-number:
INCREMENT views 1 # views is string "5"
Result: Error logged, file skipped, operation abortedArray operation on non-array:
FOR tags APPEND "new" # tags is string "old"
Result: Replaces with array: ["old", "new"]WHERE Finds No Matches
No matching items:
FOR tasks WHERE status = "archived" REMOVE
Result: No change (no items match), operation succeedsEmpty result set:
ANY tasks WHERE priority > 10 # No tasks have priority > 10
Result: Condition is false, file skippedOut of Bounds Access
Array index out of range:
Condition: tags[100] = "test" # tags only has 3 items
Result: Condition is false (index doesn't exist)Negative index beyond array:
Action: FOR tags INSERT "x" AT -50 # tags has 5 items
Result: Inserts at start (index 0)Safe Operations
Operations that won't fail:
HAS field- Always returns true/falsefield exists- Always returns true/falsefield empty- Returns false for missing/null, true for emptyFOR array WHERE ...- No error if no matchesSET field value- Creates field if missing
Operations that may fail:
INCREMENT/DECREMENT- Requires numeric fieldREPLACE- Requires string field- Deep path access - Any missing intermediate path returns false
Multiple Actions
Execute multiple actions in one rule (comma-separated):
SET status "completed", SET completed_date "{{now}}", FOR tags APPEND "done"Actions execute left-to-right in order.
Complete Examples
Update Draft Notes
Condition:
status = "draft" AND HAS tagsAction:
SET status "ready", SET reviewed_date "{{now}}"Clean Up Archived Notes
Condition:
tags contains "archived"Action:
DELETE priority, DELETE deadline, SET status "archived"Add Missing Metadata
Condition:
NOT HAS created_dateAction:
SET created_date "{{now}}", SET status "new"Conditional Tagging
Condition:
priority > 5 AND NOT tags contains "urgent"Action:
FOR tags APPEND "urgent"See Also
- Action Reference - Complete list of all operations
- Examples - Real-world usage patterns
- File Selection - Detailed file selection criteria syntax