jqfmt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package jqfmt provides formatting utilities for jq queries.

Package jqfmt provides formatting utilities for jq queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoThing

func DoThing(jqStr string, cfg_ JqFmtCfg) (string, error)

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the jq-flavored JSON encoding of v.

This method accepts only limited types (nil, bool, int, float64, *big.Int, string, []interface{}, and map[string]interface{}) because these are the possible types a gojq iterator can emit. This method marshals NaN to null, truncates infinities to (+|-) math.MaxFloat64, uses \b and \f in strings, and does not escape '<', '>', '&', '\u2028', and '\u2029'. These behaviors are based on the marshaler of jq command, and different from json.Marshal in the Go standard library. Note that the result is not safe to embed in HTML.

Types

type Array

type Array struct {
	Query *Query
}

Array ...

func (*Array) String

func (e *Array) String() string

type Bind

type Bind struct {
	Patterns []*Pattern
	Body     *Query
}

Bind ...

func (*Bind) String

func (e *Bind) String() string

type ConstArray

type ConstArray struct {
	Elems []*ConstTerm
}

ConstArray ...

func (*ConstArray) String

func (e *ConstArray) String() string

type ConstObject

type ConstObject struct {
	KeyVals []*ConstObjectKeyVal
}

ConstObject ...

func (*ConstObject) String

func (e *ConstObject) String() string

func (*ConstObject) ToValue

func (e *ConstObject) ToValue() map[string]interface{}

ToValue converts the object to map[string]interface{}.

type ConstObjectKeyVal

type ConstObjectKeyVal struct {
	Key       string
	KeyString string
	Val       *ConstTerm
}

ConstObjectKeyVal ...

func (*ConstObjectKeyVal) String

func (e *ConstObjectKeyVal) String() string

type ConstTerm

type ConstTerm struct {
	Object *ConstObject
	Array  *ConstArray
	Number string
	Str    string
	Null   bool
	True   bool
	False  bool
}

ConstTerm ...

func (*ConstTerm) String

func (e *ConstTerm) String() string

type Foreach

type Foreach struct {
	Term    *Term
	Pattern *Pattern
	Start   *Query
	Update  *Query
	Extract *Query
}

Foreach ...

func (*Foreach) String

func (e *Foreach) String() string

type Func

type Func struct {
	Name string
	Args []*Query
}

Func ...

func (*Func) String

func (e *Func) String() string

type FuncDef

type FuncDef struct {
	Name string
	Args []string
	Body *Query
}

FuncDef ...

func (*FuncDef) Minify

func (e *FuncDef) Minify()

Minify ...

func (*FuncDef) String

func (e *FuncDef) String() string

type If

type If struct {
	Cond *Query
	Then *Query
	Elif []*IfElif
	Else *Query
}

If ...

func (*If) String

func (e *If) String() string

type IfElif

type IfElif struct {
	Cond *Query
	Then *Query
}

IfElif ...

func (*IfElif) String

func (e *IfElif) String() string

type Import

type Import struct {
	ImportPath  string
	ImportAlias string
	IncludePath string
	Meta        *ConstObject
}

Import ...

func (*Import) String

func (e *Import) String() string

type Index

type Index struct {
	Name    string
	Str     *String
	Start   *Query
	End     *Query
	IsSlice bool
}

Index ...

func (*Index) String

func (e *Index) String() string

type JqFmtCfg

type JqFmtCfg struct {
	Ops []string
	Obj bool
	Arr bool
}

func ValidateConfig

func ValidateConfig(cfg JqFmtCfg) (JqFmtCfg, error)

type Label

type Label struct {
	Ident string
	Body  *Query
}

Label ...

func (*Label) String

func (e *Label) String() string

type Object

type Object struct {
	KeyVals []*ObjectKeyVal
}

Object ...

func (*Object) String

func (e *Object) String() string

type ObjectKeyVal

type ObjectKeyVal struct {
	Key       string
	KeyString *String
	KeyQuery  *Query
	Val       *Query
}

ObjectKeyVal ...

func (*ObjectKeyVal) String

func (e *ObjectKeyVal) String() string

type Pattern

type Pattern struct {
	Name   string
	Array  []*Pattern
	Object []*PatternObject
}

Pattern ...

func (*Pattern) String

func (e *Pattern) String() string

type PatternObject

type PatternObject struct {
	Key       string
	KeyString *String
	KeyQuery  *Query
	Val       *Pattern
}

PatternObject ...

func (*PatternObject) String

func (e *PatternObject) String() string

type Query

type Query struct {
	Meta     *ConstObject
	Imports  []*Import
	FuncDefs []*FuncDef
	Term     *Term
	Left     *Query
	Op       gojq.Operator
	Right    *Query
	Func     string
}

Query represents the abstract syntax tree of a jq query.

func (*Query) String

func (e *Query) String() string

type Reduce

type Reduce struct {
	Term    *Term
	Pattern *Pattern
	Start   *Query
	Update  *Query
}

Reduce ...

func (*Reduce) String

func (e *Reduce) String() string

type String

type String struct {
	Str     string
	Queries []*Query
}

String ...

func (*String) String

func (e *String) String() string

type Suffix

type Suffix struct {
	Index    *Index
	Iter     bool
	Optional bool
	Bind     *Bind
}

Suffix ...

func (*Suffix) String

func (e *Suffix) String() string

type Term

type Term struct {
	Type       gojq.TermType
	Index      *Index
	Func       *Func
	Object     *Object
	Array      *Array
	Number     string
	Unary      *Unary
	Format     string
	Str        *String
	If         *If
	Try        *Try
	Reduce     *Reduce
	Foreach    *Foreach
	Label      *Label
	Break      string
	Query      *Query
	SuffixList []*Suffix
}

Term ...

func (*Term) String

func (e *Term) String() string

type Try

type Try struct {
	Body  *Query
	Catch *Query
}

Try ...

func (*Try) String

func (e *Try) String() string

type Unary

type Unary struct {
	Op   gojq.Operator
	Term *Term
}

Unary ...

func (*Unary) String

func (e *Unary) String() string

Jump to

Keyboard shortcuts

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