lower
Converts a string value to lowercase. This is useful for case-insensitive comparisons when combined with other operators like==, startsWith, endsWith, or in.
Syntax:
- Returns
nullif the input isnull - Returns an empty string if the input is an empty string
- Returns the original value unchanged if the input is not a string (e.g., a number)
- Case-insensitive string matching in calculated attribute formulas
- Normalizing attribute values before comparison
- Building case-insensitive mapping rules with
if/inchains
startsWith
Tests whether a string starts with a given prefix. Both arguments must be strings. Syntax:lower:
- Returns
falseif either argument is not a string - The comparison is case-sensitive by default — use
lowerfor case-insensitive matching
- Categorizing products by SKU prefix
- Matching tag patterns for calculated attribute derivation
- Filtering products by attribute value prefixes
endsWith
Tests whether a string ends with a given suffix. Both arguments must be strings. Syntax:lower:
- Returns
falseif either argument is not a string - The comparison is case-sensitive by default — use
lowerfor case-insensitive matching
- Identifying bundled or grouped products by naming convention
- Matching attribute values that follow a suffix pattern
- Building calculated attributes based on string endings
count
Returns the count of elements in an array. Syntax:- Returns
nullif the input isnullor empty string - Returns the length of the array if valid
- Counting the number of variants in a product
- Calculating the number of images
- Determining the number of options available
parseDate
Parses a date string or timestamp and returns a Unix timestamp (seconds since epoch). Syntax:- String: ISO 8601 date strings, dot-separated dates (e.g., “7.26.2024”), or any format parsable by PHP’s Carbon library
- Numeric: Unix timestamps in seconds or milliseconds (automatically normalized)
null if the input is invalid or unparseable
Examples:
Parse an ISO date string:
parseDate operator supports dot-separated date formats (e.g., “7.26.2024”) with automatic disambiguation:
- Unambiguous D.M.Y: If the first number is greater than 12, it’s interpreted as day (e.g., “26.7.2024” → July 26, 2024)
- Unambiguous M.D.Y: If the second number is greater than 12, it’s interpreted as day (e.g., “7.26.2024” → July 26, 2024)
- Ambiguous dates: When both numbers are ≤ 12 (e.g., “7.6.2024”), the format defaults to M.D.Y (US convention) → July 6, 2024
- Returns
nullif input isnullor empty string - Returns
nullfor unparseable date strings (e.g., “not-a-date”) instead of throwing an exception - Automatically converts millisecond timestamps (> 10 digits) to seconds
- Handles both numeric timestamps and string dates
- Supports zero-padded dot-separated formats (e.g., “07.26.2024”)
daysSince
Calculates the number of days between a given date and the current date. Syntax:- String: Date strings (ISO 8601, dot-separated formats like “7.26.2024”, or any format parsable by PHP’s Carbon)
- Numeric: Unix timestamps in seconds or milliseconds
- JSONLogic expression: Output from
parseDateor other date operations
null if the input is invalid or unparseable
Examples:
Calculate days since publication:
parseDate, the daysSince operator supports dot-separated date formats with automatic disambiguation:
- Unambiguous D.M.Y: “26.7.2024” → July 26, 2024
- Unambiguous M.D.Y: “7.26.2024” → July 26, 2024
- Ambiguous dates: “7.6.2024” defaults to M.D.Y (US convention) → July 6, 2024
- Returns
nullif input isnullor empty string - Returns
nullfor unparseable date strings (e.g., “not-a-date”) instead of throwing an exception - Automatically converts millisecond timestamps to seconds
- Returns absolute value (always positive number of days)
- Product age calculations
- Time-based merchandising rules
- Freshness indicators for new products
- Age-based product filtering
now
Returns the current Unix timestamp in seconds. Syntax:- Real-time date comparisons
- Calculating time differences
- Dynamic time-based rules
toTimestamp
Converts a flexible date value (ISO 8601 string, dot-separated date, or numeric timestamp) to a Unix timestamp in seconds. Behaves likeparseDate but uses the extended flexible-date parser shared by the other date operators.
Syntax:
null if the value cannot be parsed.
Example:
Normalize a launch date attribute to a timestamp:
- Returns
nullfornull, empty strings, or unparseable values. - Millisecond timestamps are automatically normalized to seconds.
- Storing a consistent numeric representation of a date for downstream arithmetic.
- Comparing dates that may arrive in multiple formats.
dateDiff
Calculates the signed difference between two dates using a configurable unit. Syntax:fromDate— Any date value accepted byparseDate(ISO string, dot-separated, numeric timestamp, or a JSONLogic expression).toDate— Any date value accepted byparseDate.unit— Optional. One ofseconds,minutes,hours,days(default),weeks,months, oryears. Unit names are case-insensitive and accept singular or plural forms.
toDate - fromDate), or null if either date is invalid or the unit is not a string. The result is signed — negative when toDate is earlier than fromDate.
Example:
Days between publication and the last update:
- Returns
nullwhen either date is unparseable. - Unknown unit strings fall back to
days.
- Measuring product age in a specific unit without manual second-to-unit conversion.
- Building freshness or staleness thresholds.
- Calculating promotion windows in hours or weeks.
dateAdd
Adds an amount of time to a date and returns the resulting Unix timestamp in seconds. Syntax:date— Any date value accepted byparseDate.amount— Integer amount to add. Use a negative value to subtract.unit— Optional. One ofseconds,minutes,hours,days(default),weeks,months, oryears.
amount units, or null if the date is invalid or arguments are malformed.
Example:
Timestamp 14 days after publication:
- Computing expiration or embargo timestamps for rule gating.
- Producing future dates relative to a catalog attribute.
upper
Converts a string to uppercase. Mirrorslower but uppercases the result.
Syntax:
- Returns
nullif the input isnull. - Returns an empty string if the input is an empty string.
- Non-string values are returned unchanged.
- Normalizing attribute values to a uniform case.
- Producing display-ready labels.
trim
Removes leading and trailing whitespace from a string. Syntax:- Returns
nullor the empty string unchanged. - Non-string values are returned unchanged.
- Cleaning up values imported from spreadsheets or external sources before comparison.
normalizeWhitespace
Trims a string and collapses any run of internal whitespace into a single space. Syntax:"Premium cotton shirt" when given " Premium\tcotton shirt ".
Edge cases:
- Returns
nullor empty string unchanged. - Non-string values are returned unchanged.
- Normalizing text used as a lookup key.
- Producing stable values for hashing or grouping.
replace
Replaces all occurrences of a substring with another substring. All three arguments must be strings. Syntax:- Returns
nullif any argument is not a string.
- Removing or swapping known tokens inside attribute values.
- Producing canonical forms of identifiers.
replaceRegex
Replaces matches of a regular expression pattern with a replacement string. All three arguments must be strings. Syntax:value— Source string.pattern— A regular expression. You can provide either a bare pattern (for example,\d+) or one already wrapped in delimiters. The operator chooses a safe delimiter automatically when the pattern is bare.replacement— Replacement string. Backreferences such as$1are supported.
- Returns
nullif any argument is not a string. - Invalid regular expressions return
null.
- Cleaning noisy text attributes.
- Extracting or reformatting structured data embedded in strings.
contains
Tests whether a string contains a substring, or whether a value appears in an array. Array matching is case-insensitive; string matching is case-sensitive. Syntax:- Returns
falsewhen the haystack is neither a string nor an array. - Returns
falsewhen searching for a non-string needle inside a string haystack.
- Tag checks without having to remember the argument order of
in. - Substring searches in product descriptions or titles.
includes
Alias-style operator that behaves likecontains: checks if an array includes a value (case-insensitive) or if a string contains a substring (case-sensitive).
Syntax:
"new-arrival":
- Returns
falsewhen the haystack is neither a string nor an array.
- Reading more naturally in formulas authored by users familiar with JavaScript’s
Array.includes.
intersects
Returnstrue if two arrays share at least one value. Uses case-insensitive comparison for string values.
Syntax:
- Returns
falseif either argument is not an array.
- Matching a product against any of several tag allowlists.
- Detecting shared category memberships between two sets.
get
Reads a value from a nested array or object by dot-notation path, returning a default when the path does not exist. Syntax:target— The array or object to read from.path— A dot-notation string such as"metafields.custom.material".default— Optional value returned when the path is missing. Defaults tonull.
- Returns the default when
targetis not an array or object or whenpathis not a string.
- Safely reading nested raw Shopify data without needing chained
varcalls. - Supplying fallbacks inline.
exists
Tests whether a nested path resolves to any value (includingnull) inside an array or object.
Syntax:
- Returns
falseiftargetis not an array or object, or ifpathis not a string. - Returns
trueeven when the value at the path is explicitlynull, as long as the path itself exists.
- Feature-flag-style gates based on the presence of a metafield.
- Differentiating between “missing” and “explicitly set to null” data.
coalesce
Returns the first non-null argument. Accepts one or more arguments.
Syntax:
- Returns
nullonly if every argument isnull. - Empty strings and
0are considered valid values and short-circuit the chain.
- Supplying cascading fallbacks across multiple attributes.
- Simplifying long
or/varfallback chains.
pick
Returns a new object containing only the selected keys from a source object. Missing keys are omitted from the result. Syntax:target— An array or object to read from.keys— Either a single dot-notation key string or an array of key strings.
- Returns
nullif the target is not an array or object. - Keys that do not exist on the target are silently skipped.
- Producing a compact summary object for use in downstream calculated attributes.
- Reducing the payload size when composing objects in calculated attributes.
split
Splits a string into an array using a delimiter. Passing an empty delimiter produces an array of individual characters (multibyte-safe). Syntax:- Returns
nullif either argument is not a string.
- Normalizing CSV-style attribute values into arrays before applying
map,filter, orin. - Extracting prefixes from titles using a known separator together with
first.
first
Returns the first element of an array, ornull when the value is not an array or is empty.
Syntax:
" in ":
- Taking the leading segment from a split string.
- Picking the primary item from an ordered list of variants or images.
last
Returns the last element of an array, ornull when the value is not an array or is empty.
Syntax:
- Accessing the most recently appended entry in a list.
at
Returns the element at a specific index in an array. Supports negative indices, which count from the end. Syntax:- Returns
nullfor out-of-range indices, non-array inputs, or non-numeric indices.
- Selecting a specific position in ordered raw data.
- Reading the last or second-to-last item without first computing the length.
join
Joins an array of values into a single string using the provided delimiter (empty string by default). Syntax:- Returns
nullif the first argument is not an array or the delimiter is not a string.
- Producing display-ready strings from arrays.
- Composing keys for grouping or deduplication.
unique
Returns a new array with duplicate values removed, preserving original order. Syntax:- Returns
nullwhen the input is not an array. - Uses strict comparison rules, so
"1"and1are treated as distinct.
- Cleaning up derived arrays before using
count,join, orintersects. - Removing duplicate tag values.
length
Returns the length of a string (in bytes) or an array. Returnsnull for other types.
Syntax:
- Returns
nullfornull, numbers, booleans, and objects. - String length is measured in bytes, so multibyte characters may contribute more than one.
- Guarding against very short or very long attribute values in calculated attributes.
- Counting items in derived arrays without needing
count.
substring
Extracts a substring given a start position and optional length. Accepts negative indices (counted from the end) the same way assubstr.
Syntax:
- Returns
nullif the value is not a string, or the start or length arguments are not numeric.
- Extracting a prefix such as a category code from a SKU.
- Producing short preview snippets for display.
clamp
Restricts a numeric value to a[minimum, maximum] range.
Syntax:
[0, 100]:
- Returns
nullif any of the three arguments are not numeric.
- Normalizing relevancy or boost scores to a fixed scale.
- Enforcing guardrails on computed values.
round
Rounds a numeric value to the specified precision. Precision defaults to0.
Syntax:
- Returns
nullif either argument is not numeric.
- Producing display-friendly prices or ratings.
- Normalizing floating-point values before bucketing.
floor
Rounds a numeric value down to the nearest whole number. Syntax:- Returns
nullif the argument is not numeric.
- Creating discrete buckets from continuous numeric attributes.
- Paging-style calculations.
ceil
Rounds a numeric value up to the nearest whole number. Syntax:- Returns
nullif the argument is not numeric.
- Computing minimum counts (for example, required pages) from ratios.
- Rounding up scoring outputs.
abs
Returns the absolute value of a numeric input. Syntax:- Returns
nullif the argument is not numeric.
- Measuring magnitude of differences regardless of direction.
log1p
Returnsln(1 + value), the natural logarithm of 1 + value. This is safer than log(value) when value can be zero.
Syntax:
- Returns
nullif the argument is not numeric.
- Producing diminishing-returns-style signals in relevancy formulas.
- Stabilizing long-tail numeric distributions before boosting.
pow
Raises a base to an exponent. Syntax:- Returns
nullif either argument is not numeric.
- Custom scoring curves in calculated attributes.
- Compounding or damping signal values.