theory / sqljson

PostgreSQL-compatible SQL-standard SQL/JSON in Go

Home Page:https://theory.github.io/sqljson/

Repository from Github https://github.comtheory/sqljsonRepository from Github https://github.comtheory/sqljson

Go SQL/JSON

License GoDoc Go Report Card Build Status Code Coverage

The SQL/JSON package provides PostgreSQL-compatible SQL-standard SQL/JSON functionality in Go. For now that means jsonpath. An example:

func main() {
    src := []byte(`{
      "track": {
        "segments": [
          {
            "location":   [ 47.763, 13.4034 ],
            "start time": "2018-10-14 10:05:14",
            "HR": 73
          },
          {
            "location":   [ 47.706, 13.2635 ],
            "start time": "2018-10-14 10:39:21",
            "HR": 135
          }
        ]
      }
    }`)

    // Parse the JSON.
    var value any
    if err := json.Unmarshal(src, &value); err != nil {
        log.Fatal(err)
    }

    // Parse the SQL-standard jsonpath query.
    p, err := path.Parse(`$.track.segments[*] ? (@.HR > 130)."start time"`)
    if err != nil {
        log.Fatal(err)
    }

    // Execute the query against the JSON.
    items, err := p.Query(context.Background(), value)
    if err != nil {
        log.Fatal(err)
    }

    // Print the results.
    fmt.Printf("%v\n", items)
    // Output: [2018-10-14 10:39:21]
}

See the path README for a complete description of the SQL/JSON path language, and the Go doc for usage and examples.

Or take the ๐Ÿ› Playground for a spin (direct link for above example). Implemented as a single-page stateless JavaScript and TinyGo-compiled Wasm app.

Copyright

Copyright ยฉ 1996-2025 The PostgreSQL Global Development Group

Copyright ยฉ 2024-2025 David E. Wheeler

About

PostgreSQL-compatible SQL-standard SQL/JSON in Go

https://theory.github.io/sqljson/

License:Other


Languages

Language:Go 98.5%Language:Yacc 1.1%Language:Perl 0.2%Language:Makefile 0.2%