File: gojq.go

package info (click to toggle)
golang-github-wader-gojq 0.0~git20231105.2b6d9e2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 960 kB
  • sloc: yacc: 642; makefile: 84
file content (69 lines) | stat: -rw-r--r-- 2,065 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Package gojq provides the parser and the interpreter of gojq.
// Please refer to [Usage as a library] for introduction.
//
// [Usage as a library]: https://github.com/itchyny/gojq#usage-as-a-library
package gojq

// TODO: use in TypeOf?
const (
	JQTypeArray   = "array"
	JQTypeBoolean = "boolean"
	JQTypeNull    = "null"
	JQTypeNumber  = "number"
	JQTypeObject  = "object"
	JQTypeString  = "string"
)

// JQValue represents something that can be a jq value
// All functions with return type any can return error on error
// array = []any
// boolean = bool
// null = nil
// number = int | float64 | *big.Int
// object = map[string]any
// string = string
// value = number | boolean | string | array | object | null
type JQValue interface {
	// JQValueLength is length of value, ex: value | length
	JQValueLength() any // int

	// JQValueSliceLen slice length
	JQValueSliceLen() any // int

	// JQValueIndex look up index for value, ex: value[index]
	// index -1 outside after slice, -2 outside before slice
	JQValueIndex(index int) any // value

	// JQValueSlice slices value, ex: value[start:end]
	// start and end indexes are translated and clamped using JQValueSliceLen
	JQValueSlice(start int, end int) any // []any

	// JQValueKey look up key value of value: ex: value[name]
	JQValueKey(name string) any // value

	// JQValueEach each of value, ex: value[]
	JQValueEach() any // []PathValue

	// JQValueKeys keys for value, ex: value | keys
	JQValueKeys() any // []string

	// JQValueHas check if value has key, ex: value | has(key)
	JQValueHas(key any) any // bool

	// JQValueType type of value, ex: value | type
	JQValueType() string // a JQType* constant

	// JQValueToNumber is value represented as a number, ex: value | tonumber
	JQValueToNumber() any // number

	// JQValueToString is value represented as a string, ex: value | tostring
	JQValueToString() any // string

	// JQValue value represented as a gojq compatible value
	JQValueToGoJQ() any // value
}

// PathValue is a part of a jq path expression
type PathValue struct {
	Path, Value any
}