Skip to content
kode4foodPublic

About

A small, pure expression language for JSON values in Go

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Argyll Expressions

Build Status Code Coverage Maintainability GitHub

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}]

Go API

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@latest
total, err := argex.Eval(`quantity * price`, map[string]any{
    "quantity": 3, "price": 3.95,
})
// total: 11.85

Compile and reuse a program or bind Go functions to make application-specific operations available to rules.

Command Line

go install github.com/kode4food/argex/cmd/aq@latest
echo '{"quantity":3,"price":3.95}' | aq 'quantity * price'
# 11.85

Documentation

Development

make pre-commit
go test -race ./...
go test ./internal/engine -run '^$' -fuzz FuzzExpression -fuzztime=10s
go test -run '^$' -bench . -benchmem

The 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 ./....

About

A small, pure expression language for JSON values in Go

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages