MCPcopy Index your code
hub / github.com/blues/jsonata-go

github.com/blues/jsonata-go @v1.5.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.5.4 ↗ · + Follow
1,450 symbols 4,169 edges 48 files 228 documented · 16% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

JSONata in Go

Package jsonata is a query and transformation language for JSON. It's a Go port of the JavaScript library JSONata.

It currently has feature parity with jsonata-js 1.5.4. As well as a most of the functions added in newer versions. You can see potentially missing functions by looking at the jsonata-js changelog.

Install

go get github.com/blues/jsonata-go

Usage

import (
    "encoding/json"
    "fmt"
    "log"

    jsonata "github.com/blues/jsonata-go"
)

const jsonString = `
    {
        "orders": [
            {"price": 10, "quantity": 3},
            {"price": 0.5, "quantity": 10},
            {"price": 100, "quantity": 1}
        ]
    }
`

func main() {

    var data interface{}

    // Decode JSON.
    err := json.Unmarshal([]byte(jsonString), &data)
    if err != nil {
        log.Fatal(err)
    }

    // Create expression.
    e := jsonata.MustCompile("$sum(orders.(price*quantity))")

    // Evaluate.
    res, err := e.Eval(data)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(res)
    // Output: 135
}

JSONata Server

A locally hosted version of JSONata Exerciser for testing is available here.

JSONata tests

A CLI tool for running jsonata-go against the JSONata test suite is available here.

Contributing

We love issues, fixes, and pull requests from everyone. Please run the unit-tests, staticcheck, and goimports prior to submitting your PR. By participating in this project, you agree to abide by the Blues Inc code of conduct.

For details on contributions we accept and the process for contributing, see our contribution guide.

In addition to the Go unit tests there is also a test runner that will run against the jsonata-js test suite in the jsonata-test directory. A number of these tests currently fail, but we're working towards feature parity with the jsonata-js reference implementation. Pull requests welcome!

If you would like to contribute to this library a good first issue would be to run the jsonata-test suite, and fix any of the tests not passing.

Extension points exported contracts — how you extend this code

Node (Interface)
Node represents an individual node in a syntax tree. [34 implementers]
jparse/node.go
Variant (Interface)
Variant (golint) [2 implementers]
jtypes/types.go
Optional (Interface)
Optional (golint) [2 implementers]
jtypes/types.go
Callable (Interface)
Callable (golint) [1 implementers]
jtypes/types.go
Convertible (Interface)
Convertible (golint) [1 implementers]
jtypes/types.go
ArgHandler (FuncType)
ArgHandler (golint)
jtypes/types.go

Core symbols most depended-on inside this repo

Len
called by 63
eval.go
Resolve
called by 50
jtypes/funcs.go
optimize
called by 39
jparse/node.go
NewOptionalInt
called by 37
jtypes/types.go
eval
called by 36
eval.go
IsArray
called by 32
jtypes/funcs.go
consume
called by 27
jparse/jparse.go
AsNumber
called by 25
jtypes/funcs.go

Shape

Function 1,102
Method 213
Struct 98
TypeAlias 22
FuncType 8
Interface 7

Languages

Go71%
TypeScript29%

Modules by API surface

jsonata-server/site/assets/js/codemirror.min.js328 symbols
jsonata_test.go183 symbols
jparse/node.go160 symbols
jsonata-server/site/assets/js/javascript.min.js79 symbols
eval.go65 symbols
callable.go55 symbols
jlib/jxpath/formatdate.go54 symbols
jtypes/types.go45 symbols
callable_test.go43 symbols
jlib/jxpath/formatnumber.go34 symbols
jparse/jparse_test.go31 symbols
jlib/object_test.go31 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add jsonata-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact