-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick.go
More file actions
92 lines (82 loc) · 2.38 KB
/
Copy pathquick.go
File metadata and controls
92 lines (82 loc) · 2.38 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package jsonptr
// Get returns the value for the specified location in the document.
func Get(document interface{}, ptr string) (interface{}, error) {
p, err := New(ptr)
if err != nil {
return nil, err
}
return p.Get(document)
}
// GetBool returns the value for the specified location in the document as a string, or false if not accessible.
func GetBool(document interface{}, ptr string) bool {
p, err := New(ptr)
if err != nil {
return false
}
return p.GetBool(document)
}
// GetString returns the value for the specified location in the document as a string, or an empty string if not accessible.
func GetString(document interface{}, ptr string) string {
p, err := New(ptr)
if err != nil {
return ""
}
return p.GetString(document)
}
// GetNumber returns the value for the specified location in the document as a string, or 0 if not accessible.
func GetNumber(document interface{}, ptr string) float64 {
p, err := New(ptr)
if err != nil {
return 0
}
return p.GetNumber(document)
}
// Has returns a boolean indicating whether the pointer location exists in
// the provided document.
func Has(document interface{}, ptr string) bool {
p, err := New(ptr)
if err != nil {
return false
}
return p.Exists(document)
}
// Set sets the specified location in the document to the provided value.
// See also, Pointer.Set
func Set(document interface{}, ptr string, val interface{}) error {
p, err := New(ptr)
if err != nil {
return err
}
return p.Set(document, val)
}
// Force sets the specified location in the document to the provided value
// See also, Pointer.Force
func Force(document interface{}, ptr string, val interface{}) error {
p, err := New(ptr)
if err != nil {
return err
}
return p.Force(document, val)
}
/*
Flatten compacts the provided json document into a map[string]interface{},
with all keys at the root level. See also Compactor.Flatten
*/
func Flatten(target interface{}) map[string]interface{} {
c := &Compactor{}
return c.Flatten(target)
}
/*
List compacts the provided json document into a slice of PointerValues. See
also Compactor.List
*/
func List(target interface{}) []PointerValue {
c := &Compactor{}
return c.List(target)
}
// Expand expands a map with keys containing json pointers into a full
// json.Marshal-able document. See also Expander.Expand
func Expand(values map[string]interface{}) (interface{}, error) {
e := &Expander{}
return e.Expand(values)
}