pub enum AstNode {
Show 29 variants
String(String),
Name(String),
Number(f64),
Boolean(bool),
Null,
Undefined,
Placeholder,
Regex {
pattern: String,
flags: String,
},
Variable(String),
ParentVariable(String),
Path {
steps: Vec<PathStep>,
},
Binary {
op: BinaryOp,
lhs: Box<AstNode>,
rhs: Box<AstNode>,
},
Unary {
op: UnaryOp,
operand: Box<AstNode>,
},
Function {
name: String,
args: Vec<AstNode>,
is_builtin: bool,
},
Call {
procedure: Box<AstNode>,
args: Vec<AstNode>,
},
Lambda {
params: Vec<String>,
body: Box<AstNode>,
signature: Option<String>,
thunk: bool,
},
Array(Vec<AstNode>),
Object(Vec<(AstNode, AstNode)>),
ObjectTransform {
input: Box<AstNode>,
pattern: Vec<(AstNode, AstNode)>,
},
Block(Vec<AstNode>),
Conditional {
condition: Box<AstNode>,
then_branch: Box<AstNode>,
else_branch: Option<Box<AstNode>>,
},
Wildcard,
Descendant,
Predicate(Box<AstNode>),
ArrayGroup(Vec<AstNode>),
FunctionApplication(Box<AstNode>),
Sort {
input: Box<AstNode>,
terms: Vec<(AstNode, bool)>,
},
IndexBind {
input: Box<AstNode>,
variable: String,
},
Transform {
location: Box<AstNode>,
update: Box<AstNode>,
delete: Option<Box<AstNode>>,
},
}Expand description
AST Node types
This enum represents all possible node types in a JSONata expression AST. The structure closely mirrors the JavaScript implementation to facilitate maintenance and upstream synchronization.
Variants§
String(String)
String literal (e.g., “hello”, ‘world’)
Name(String)
Field/property name in path expressions (e.g., foo in foo.bar) This is distinct from String: Name is a field access, String is a literal value
Number(f64)
Number literal
Boolean(bool)
Boolean literal
Null
Null literal
Undefined
Undefined literal (distinct from null in JavaScript semantics) In JSONata, undefined represents “no value” and propagates through expressions
Placeholder
Placeholder for partial application (?) When used as a function argument, creates a partially applied function
Regex
Regex literal (e.g., /pattern/flags)
Variable(String)
Variable reference (e.g., $var)
ParentVariable(String)
Parent variable reference (e.g., $$)
Path
Path expression (e.g., foo.bar) Each step can have stages (like predicates) attached
Binary
Binary operation
Unary
Unary operation
Function
Function call by name
Fields
Call
Call an arbitrary expression as a function
Used for IIFE patterns like (function($x){...})(5) or chained calls
The procedure can be any expression that evaluates to a function
Lambda
Lambda function definition
Fields
Array(Vec<AstNode>)
Array constructor
Object(Vec<(AstNode, AstNode)>)
Object constructor
ObjectTransform
Object transform (postfix object constructor): expr{key: value} Transforms the input using the object pattern
Block(Vec<AstNode>)
Block expression
Conditional
Conditional expression (? :)
Wildcard
Wildcard operator (*) in path expressions
Descendant
Descendant operator (**) in path expressions
Predicate(Box<AstNode>)
Array filter/predicate [condition] Can be an index (number) or a predicate (boolean expression)
ArrayGroup(Vec<AstNode>)
Array grouping in path expression .[expr] Like Array but doesn’t flatten when used in paths
FunctionApplication(Box<AstNode>)
Function application in path expression .(expr) Maps expr over the current value, with $ referring to each element
Sort
Sort operator in path expression ^(expr) Sorts the current value by evaluating expr for each element expr can be prefixed with < (ascending, default) or > (descending)
Fields
IndexBind
Index binding operator #$var Binds the current array index to the specified variable during path traversal For example: arr#$i.field binds the index to $i for each element
Fields
Transform
Transform operator |location|update[,delete]| Creates a function that transforms objects by:
- Evaluating location to find objects to modify
- Applying update (object constructor) to each matched object
- Optionally deleting fields specified in delete array