aboutsummaryrefslogtreecommitdiff
path: root/model/node.go
blob: 9a55dae97c1ef316209eec9465d297f08f3abd83 (plain) (blame)
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
package model

// Node of JSON tree
type Node interface {
	Type() NodeType
	MarshalJSON() ([]byte, error)
	Set(v any) error
}

// NewNode creates new node from value
func NewNode(value any) Node {
	switch value := value.(type) {
	case string:
		return &StringNode{
			Value: value,
		}
	case float64:
		return &NumberNode{
			Value: value,
		}
	case int:
		return &NumberNode{
			Value: float64(value),
		}
	case NodeObjectValue:
		return &ObjectNode{
			Value: value,
		}
	case NodeArrayValue:
		return &ArrayNode{
			Value: value,
		}
	case bool:
		return &BooleanNode{
			Value: value,
		}
	default:
		return NullNode{}
	}
}