This repository is an updated fork of the original blues/jsonata-go library, upgraded to support JSONata 2.2.2 specifications and WebAssembly
Package jsonata is a query and transformation language for JSON data implemented in pure Go. It is a high-performance port of the reference JavaScript implementation, JSONata.
This repository maintains 100% feature compliance with jsonata-js v2.2.2, passing all 1,700+ upstream test cases with zero skips or failures.
- Full JSONata 2.2.2 Parity: Complete support for path navigation, wildcards, descendants, predicates, sorting, grouping, lambdas, closures, transforms, regex, and the 50+ standard library functions.
- Pure Go: Zero external runtime dependencies.
- WebAssembly (WASM) Support: Ready-to-build WASM entry point for in-browser evaluation and UI playgrounds with panic recovery and AST caching.
- Included Utilities:
jsonata-server: A locally hosted JSONata Exerciser web application.jsonata-test: CLI runner to evaluate the engine directly against the officialjsonata-jstest suite.
Requires Go 1.27+.
go get github.com/darius-lesch/jsonata-go/v2
package main
import (
jsonv2 "encoding/json/v2"
"fmt"
"log"
jsonata "github.com/darius-lesch/jsonata-go/v2"
)
const jsonString = `
{
"orders": [
{"price": 10, "quantity": 3},
{"price": 0.5, "quantity": 10},
{"price": 100, "quantity": 1}
]
}
`
func main() {
var data any
// Decode JSON
if err := jsonv2.Unmarshal([]byte(jsonString), &data); err != nil {
log.Fatal(err)
}
// Compile JSONata expression
expr, err := jsonata.Compile("$sum(orders.(price * quantity))")
if err != nil {
log.Fatal(err)
}
// Evaluate against data payload
res, err := expr.Eval(data)
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
// Output: 135
}jsonata-go includes a WebAssembly entry point inside ./wasm/ designed for client-side browser evaluation.
GOOS=js GOARCH=wasm go build -ldflags="-s -w" -trimpath -o jsonata.wasm ./wasm/
The compiled WASM module exposes the _jsonataGoEval global function on window:
// _jsonataGoEval(expressionString, jsonDataString) -> string | Error
try {
const resultJson = window._jsonataGoEval(
"$sum(orders.(price * quantity))",
JSON.stringify(payload)
);
console.log(JSON.parse(resultJson)); // 135
} catch (err) {
console.error("Evaluation Error:", err.message);
}A locally hosted version of the JSONata Exerciser web UI for interactively testing expressions against live JSON payloads. Static assets (HTML, CSS, JavaScript, and CodeMirror editor) are embedded directly into the binary, allowing jsonata-server to be executed from any working directory without external file dependencies.
# Install the binary locally:
go install ./jsonata-server
# Or install the latest release remotely:
# go install github.com/darius-lesch/jsonata-go/v2/jsonata-server@latest
# Launch the server (default port 8080):
jsonata-server -port=8080
# Or run directly without installation:
go run ./jsonata-server -port=8080Navigate to http://localhost:8080 in your browser to use the interactive exerciser.
| Flag | Default | Description |
|---|---|---|
-port |
8080 |
The port number to serve HTTP traffic on. |
-site |
"" |
Optional path to a custom directory to serve static files from (overriding embedded assets; useful for frontend development). |
GET /: Serves the interactive JSONata Exerciser web application.POST /eval: Evaluates a JSONata expression against a JSON payload. Expectsapplication/x-www-form-urlencodedor multipart form data:expr: The JSONata query/expression string.json: The JSON input document string.
GET /bench: Executes a predefined benchmark expression against sample telemetry data and returns"success".
A CLI utility used to run jsonata-go directly against the official jsonata-js test-suite.
- Install the CLI runner:
go install github.com/darius-lesch/jsonata-go/v2/jsonata-test@latest
- Clone the official
jsonata-jsrepository:
git clone https://github.com/jsonata-js/jsonata.git
cd jsonata
git checkout v2.2.2
- Execute the test runner against the suite:
jsonata-test ./test/test-suite
Contributions, bug reports, and pull requests are welcome! Prior to submitting a PR, please ensure all unit tests pass and code is formatted cleanly:
go test ./...
go fmt ./...