jsonpath

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package jsonpath renders the "column->a->b[0]" selector syntax into the JSON path literals and operands each database expects. The functions are pure string builders; quoting here is what keeps a path from breaking out of its SQL literal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(v any) (string, error)

Encode marshals v as JSON without HTML escaping (<, > and & stay literal).

func IsContainer

func IsContainer(v any) bool

IsContainer reports values that encode as a JSON object or array (maps, structs, slices other than []byte), as opposed to a scalar.

func IsSelector

func IsSelector(s string) bool

IsSelector reports whether s uses the "->" JSON path syntax.

func LastSegment

func LastSegment(s string) string

LastSegment returns what follows the last "." ("tbl.col" -> "col").

func ParseIndexSegment

func ParseIndexSegment(last string) (key string, index int, ok bool)

ParseIndexSegment recognises a path's last segment as an array index, either a bare integer ("2") or a keyed one ("tags[-2]"). key is what precedes the index ("" for a bare integer).

func Path

func Path(v string) string

Path renders a MySQL/SQLite JSON path literal for "a->b[0]": '$."a"."b"[0]'. Single quotes are doubled (and backslashes before them dropped) so the literal cannot be escaped.

func PgAttributes

func PgAttributes(path []string, quote string) []string

PgAttributes turns path segments into Postgres path operands, expanding "key[0][1]" and quoting non-integers with quote ("'" for -> operands, `"` inside a '{...}' path).

func SplitKey

func SplitKey(key string) (column string, path []string)

SplitKey splits "tbl.col->a->b" into the column part and its path segments.

Types

This section is empty.

Jump to

Keyboard shortcuts

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