sqljson

module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2026 License: PostgreSQL

README

Go SQL/JSON

License GoDoc 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.

Strict No LLM/No AI Policy

This software is 100% made by humans for humans and welcomes human contributions. That means:

  • No LLM-generated content, whether it be code or prose.
  • No paraphrasing LLM-generated content.
  • No LLMs for editing, including fixing spelling or grammatical errors.
  • No LLMs for translation. English is encouraged, but not required. You are welcome to post in your native language and rely on others to have their own translation tools of choice to interpret your words.
  • No LLMs for brainstorming and then sharing the results of that brainstorming, even if you create the prose. If you use a chatbot to give you advice on a comment on the issue tracker, that comment is unwelcome.
  • No LLMs for finding bugs.
  • No talking about use of chatbot/LLM services.

Borrowed from the Zig Code of Conduct.

Copyright © 1996-2025 The PostgreSQL Global Development Group

Copyright © 2024-2026 David E. Wheeler

Directories

Path Synopsis
internal
wasm command
Package main performs a basic JSONPath query in order to test WASM compilation.
Package main performs a basic JSONPath query in order to test WASM compilation.
Package path provides PostgreSQL 18-compatible SQL/JSON path parsing and execution.
Package path provides PostgreSQL 18-compatible SQL/JSON path parsing and execution.
ast
Package ast provides an abstract syntax tree for SQL/JSON paths.
Package ast provides an abstract syntax tree for SQL/JSON paths.
exec
Package exec provides the routines for SQL/JSON path execution.
Package exec provides the routines for SQL/JSON path execution.
parser
Package parser parses SQL/JSON paths.
Package parser parses SQL/JSON paths.
types
Package types provides PostgresSQL-compatible data types for SQL/JSON Path execution.
Package types provides PostgresSQL-compatible data types for SQL/JSON Path execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL