json

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package json implements the RedisJSON (JSON.*) command family on top of the effects engine's virtual-partition keys. This file defines the internal, dependency-free JSON value model. Object member order is preserved (a RedisJSON requirement) by storing members as an ordered slice, not a Go map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serialize

func Serialize(v *Value) []byte

Serialize renders v to canonical compact JSON bytes. This is the form stored in scalar leaf partitions and returned for legacy single-value replies.

func SerializePretty

func SerializePretty(v *Value, opts PrintOpts) []byte

SerializePretty renders v with JSON.GET formatting options. With an empty PrintOpts it is byte-identical to Serialize.

Types

type Kind

type Kind uint8

Kind enumerates the JSON value kinds. RedisJSON distinguishes "integer" from "number", so integral and fractional numbers are separate kinds.

const (
	KindNull Kind = iota
	KindBool
	KindInt
	KindFloat
	KindString
	KindArray
	KindObject
)

type Member

type Member struct {
	Key string
	Val *Value
}

Member is one key/value pair of an object, in insertion order.

type Path

type Path struct {
	JSONPath bool
	// contains filtered or unexported fields
}

Path is a parsed JSON path. JSONPath ($-prefixed) resolves to all matches and is reported as an array; legacy (leading '.' or bare) resolves to the first match and is reported bare.

func ParsePath

func ParsePath(s string) (*Path, error)

ParsePath parses a RedisJSON path in either dialect. Both dialects share the full grammar — object/array steps, wildcard (* / [*]), array slice ([start:end:step]), union ([a,b] / ['x','y']), recursive descent (..), and filter ([?(@.x>1)]). The dialects differ only in how the resolved matches are reported (JSONPath → array of all; legacy → the first match bare).

func (*Path) IsRoot

func (p *Path) IsRoot() bool

IsRoot reports whether the path addresses the document root.

type PrintOpts

type PrintOpts struct {
	Indent  string // inserted once per nesting level
	Newline string // inserted after the opening brace/bracket and each element
	Space   string // inserted after ':' in objects
}

PrintOpts controls JSON.GET pretty-printing. All-empty == compact.

type Value

type Value struct {
	Kind  Kind
	Bool  bool
	Int   int64
	Float float64
	Str   string
	Arr   []*Value
	Obj   []Member
}

Value is the internal JSON model. Exactly one payload field is meaningful per Kind. Objects keep insertion order via the Obj slice.

func Parse

func Parse(data []byte) (*Value, error)

Parse decodes JSON bytes into the ordered model. It streams tokens via encoding/json so object key order is preserved (json.Unmarshal into a map would lose it), and uses UseNumber so integers vs floats are classified without float64 precision loss on large integers.

func (*Value) DeepCopy

func (v *Value) DeepCopy() *Value

DeepCopy returns an independent clone of v.

func (*Value) IsContainer

func (v *Value) IsContainer() bool

IsContainer reports whether v is an object or array (vs a scalar leaf).

func (*Value) TypeName

func (v *Value) TypeName() string

TypeName returns the RedisJSON type string reported by JSON.TYPE.

Jump to

Keyboard shortcuts

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