ExprML is a programming language for representing and evaluating expressions in JSON format.
The language specification is defined by a JSON Schema, available here:
- JSON: https://github.com/exprml/exprml-language/blob/main/schema.json
- YAML: https://github.com/exprml/exprml-language/blob/main/schema.yaml
ExprML realizes the following concepts to make it suitable as an expression language used in configuration files:
- JSON-based:
- ExprML can represent expressions in JSON (and JSON-compatible YAML).
- ExprML expressions can be evaluated as JSON values.
- ExprML expressions can be checked and auto-completed statically using the JSON Schema.
- Embeddable:
- Interpleters implementing ExprML are available as libraries.
- JSON Schema of ExpreML can be referenced from exsisting tools and other JSON Schemas.
- Multi-language support
- Libraries implementing the interpreters are provided in various programming languages.
- Go: https://github.com/exprml/exprml-go
- PHP: https://github.com/exprml/exprml-php
- Dart: https://github.com/exprml/exprml_dart
- TypeScript and JavaScript: https://github.com/exprml/exprml-ts
- JVM languages including Kotlin and Java: https://github.com/exprml/exprml-jvm
https://github.com/exprml/exprml-cli
true
# => true1089
# => 1089'`ExprML`'
# => "ExprML"arr: [1, 2, 3]
# => [1, 2, 3]obj:
id: 1234567
name: "`ExprML`"
# => {"id": 1234567, "name": "ExprML"}eval:
$hello_func:
$target: $name_var
where:
- $name_var: "`ExprML`"
- $hello_func($target):
cat: ["`Hello, `", $target, "`!`"]
# => "Hello, ExprML!"not: true
# => false| operator | operand | result |
|---|---|---|
len |
string, array, object | length of the collection |
not |
boolean | negation of the operand |
flat |
array of array | flattened array |
floor |
number | maximum integer which is less than or equal to the operand |
ceil |
number | minimum integer which is greater than or equal to the operand |
abort |
string | It fails the evaluation with a given message. |
gte: [ 1234, 567 ]
# => true| operator | operands | result |
|---|---|---|
sub |
number | subtraction of the operands |
div |
number | division of the operands |
eq |
number, boolean, string, array, object | equality of the operands |
neq |
number, boolean, string, array, object | negation of the equality of the operands |
lt |
comparable values, which are numbers, strings, booleans, or arrays of comparable values | whether the left operand is less than the right operand |
lte |
comparable values | whether the left operand is less than or equal to the right operand |
gt |
comparable values | whether the left operand is greater than the right operand |
gte |
comparable values | whether the left operand is greater than or equal to the right operand |
add: [ 1, 2, 3 ]
# => 6| operator | operands | result |
|---|---|---|
add |
number | sum of the operands |
mul |
number | product of the operands |
and |
boolean | logical conjunction of operands |
or |
boolean | logical disjunction of the operands |
cat |
string | concatenation of the operands |
min |
number | minimum number in the operands |
max |
number | maximum number is the operands |
merge |
object | merged object of the operands |
cases:
- when: false
then: 1
- when: true
then: 2
- otherwise: 3
# => 2Collection is one of string, array, and object.
for($idx, $elem): "`abc`"
do: $idx
if:
neq: [$elem, "`b`"]
# => [0, 2]for($idx, $elem):
arr: [5, 6, 7]
do: $idx
if:
neq: [$elem, 6]
# => [0, 2]for($key, $val):
obj:
id: 123
name: "`ExprML`"
do: $key
if:
neq: [$val, 123]
# => {"name": "ExprML"}get: 1
from: "`abc`"
# => "b"get: 1
from:
arr: [1, 2, 3]
# => 2get: "`name`"
from:
obj:
id: 123
name: "`ExprML`"
# => "ExprML"