JSONLogic Integration
datafake-rs is built on top of datalogic-rs, a high-performance JSONLogic implementation. This means you can use all standard JSONLogic operators alongside the fake operator.
Core Operators
Variable Access
Use var to access variables or nested data:
{"var": "variableName"}
{"var": "nested.path.to.value"}
String Concatenation
Use cat to combine strings:
{"cat": ["Hello, ", {"fake": ["name"]}, "!"]}
Conditional Logic
Use if for conditional generation:
{"if": [condition, then_value, else_value]}
Comparison Operators
| Operator | Description | Example |
|---|---|---|
== | Equal | {"==": [1, 1]} |
!= | Not equal | {"!=": [1, 2]} |
> | Greater than | {">": [5, 3]} |
>= | Greater or equal | {">=": [5, 5]} |
< | Less than | {"<": [3, 5]} |
<= | Less or equal | {"<=": [5, 5]} |
Logical Operators
and
All conditions must be true:
{"and": [condition1, condition2, ...]}
or
At least one condition must be true:
{"or": [condition1, condition2, ...]}
not / !
Negates a condition:
{"!": [condition]}
{"not": [condition]}
Arithmetic Operators
| Operator | Description | Example |
|---|---|---|
+ | Add | {"+": [1, 2, 3]} → 6 |
- | Subtract | {"-": [10, 3]} → 7 |
* | Multiply | {"*": [2, 3, 4]} → 24 |
/ | Divide | {"/": [10, 2]} → 5 |
% | Modulo | {"%": [10, 3]} → 1 |
Array Operators
map
Transform each element:
{"map": [array, transformation]}
filter
Filter elements by condition:
{"filter": [array, condition]}
reduce
Reduce array to single value:
{"reduce": [array, reducer, initial_value]}
merge
Combine arrays:
{"merge": [array1, array2]}
String Operators
cat
Concatenate strings:
{"cat": ["string1", "string2", ...]}
substr
Extract substring:
{"substr": ["string", start, length]}
Combining with fake
You can combine any JSONLogic operator with fake:
Complex Example
Learn More
For complete JSONLogic documentation, see: