Argyll Expressions is a language for querying and transforming JSON with JavaScript-style syntax.
Take a list of orders.
{
"orders": [
{"id": "A", "paid": true, "quantity": 3, "price": 3.95},
{"id": "B", "paid": false, "quantity": 1, "price": 6.50}
]
}| Expression | Result |
|---|---|
orders[0].id |
"A" |
orders[0].quantity * orders[0].price |
11.85 |
orders[1].paid && orders[1].quantity > 0 |
false |
To get the total for every paid order, pipe the array through filter and map.
orders
| filter order: order.paid
| map order: {
id: order.id,
total: order.quantity * order.price,
}[{"id": "A", "total": 11.85}]Argyll Expressions is designed to work directly with the values Go’s encoding/json produces when it unmarshals JSON into an any.
go get github.com/kode4food/argex@latesttotal, err := argex.Eval(`quantity * price`, map[string]any{
"quantity": 3, "price": 3.95,
})
// total: 11.85Compile and reuse a program or bind Go functions to make application-specific operations available to rules.
go install github.com/kode4food/argex/cmd/aq@latest
echo '{"quantity":3,"price":3.95}' | aq 'quantity * price'
# 11.85- Getting started covers installation, the Go API, and value representation.
- Command line covers the
aqtool and its flags. - Collections explains
map,filter,any,all,reduce, and pipelines. - Arrays and objects covers literals, spreads, and computed keys.
- Conditional selection describes
case, with conditions or a subject to match. - Local bindings covers
let, destructuring, and defaults. - Missing values explains optional access,
??, and missing versus null. - Operators lists precedence, equality, and membership rules.
- Functions documents every built-in function.
- Type checking covers compile-time checks and result types.
- Errors and limits lists error sentinels and evaluation limits.
- Grammar gives the complete syntax in EBNF.
make pre-commit
go test -race ./...
go test ./internal/engine -run '^$' -fuzz FuzzExpression -fuzztime=10s
go test -run '^$' -bench . -benchmemThe grammar is in grammar.ebnf.
Add language behavior tests to testdata/compliance. Each JSON case specifies an expression, input, and expected result or error. Run them with go test ./....
