-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
49 lines (37 loc) · 862 Bytes
/
json.go
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
// Package types - Content managed by Project Forge, see [projectforge.md] for details.
package types
import "admini.dev/admini/app/util"
const KeyJSON, objStr = "json", "{}"
type JSON struct {
IsObject bool `json:"obj,omitempty"`
IsArray bool `json:"arr,omitempty"`
}
var _ Type = (*JSON)(nil)
func (x *JSON) Key() string {
return KeyJSON
}
func (x *JSON) Sortable() bool {
return false
}
func (x *JSON) Scalar() bool {
return false
}
func (x *JSON) String() string {
return x.Key()
}
func (x *JSON) From(v any) any {
if s, ok := v.(string); ok {
ret, _ := util.FromJSONAny([]byte(s))
return ret
}
return invalidInput(x.Key(), v)
}
func (x *JSON) Default(string) any {
return objStr
}
func NewJSON() *Wrapped {
return Wrap(&JSON{})
}
func NewJSONArgs(obj bool, arr bool) *Wrapped {
return Wrap(&JSON{IsObject: obj, IsArray: arr})
}