-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathtype.go
More file actions
31 lines (29 loc) · 627 Bytes
/
type.go
File metadata and controls
31 lines (29 loc) · 627 Bytes
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
package gojq
import (
"encoding/json"
"fmt"
"math/big"
)
// TypeOf returns the jq-flavored type name of v.
//
// This method is used by built-in type/0 function, and accepts only limited
// types (nil, bool, int, float64, *big.Int, json.Number, string, []any, and
// map[string]any).
func TypeOf(v any) string {
switch v.(type) {
case nil:
return "null"
case bool:
return "boolean"
case int, float64, *big.Int, json.Number:
return "number"
case string:
return "string"
case []any:
return "array"
case map[string]any:
return "object"
default:
panic(fmt.Sprintf("invalid type: %[1]T (%[1]v)", v))
}
}