Skip to content

Open Source Go version of JSONata - with Xiatech

License

Notifications You must be signed in to change notification settings

mvandergrift/jsonata-go

This branch is 1 commit ahead of xiatechs/jsonata-go:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

cc5befe · Oct 7, 2024

History

66 Commits
Mar 28, 2023
Feb 17, 2022
Apr 26, 2024
Oct 2, 2023
Dec 13, 2023
Dec 13, 2023
May 10, 2021
May 10, 2021
Nov 17, 2023
May 10, 2021
Sep 19, 2022
Apr 22, 2021
Dec 13, 2023
Dec 13, 2023
Oct 2, 2023
May 10, 2021
Dec 13, 2023
May 18, 2023
Dec 13, 2023
Dec 12, 2023
Oct 2, 2023
Dec 13, 2023
Sep 19, 2022
Apr 26, 2024
Apr 26, 2024
Oct 7, 2024
Apr 17, 2024
Oct 2, 2023

Repository files navigation

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/xiatechs/jsonata-go

Usage

import (
	"github.com/goccy/go-json"
	"fmt"
	"log"

	jsonata "github.com/xiatechs/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.

About

Open Source Go version of JSONata - with Xiatech

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 97.3%
  • JavaScript 1.4%
  • HTML 1.1%
  • CSS 0.2%