forked from bombsimon/jtd-infer-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infer_with_hints.go
36 lines (32 loc) · 980 Bytes
/
infer_with_hints.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
package main
import (
"encoding/json"
"github.com/bombsimon/jtd-infer-go"
)
func main() {
rows := []string{
`{
"name":"Joe",
"age":52,
"work":{"department": "sales"},
"values":{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]},
"discriminator":[{"type":"s", "value":"foo"},{"type":"n", "value":3.14}]
}`,
`{
"name":"Jane",
"age":48,
"work":{"department": "engineering"},
"values":{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, -2000]},
"discriminator":[{"type":"s", "value":"foo"},{"type":"n", "value":3.14}]
}`,
}
hints := jtdinfer.Hints{
DefaultNumType: jtdinfer.NumTypeUint32,
Enums: jtdinfer.NewHintSet().Add([]string{"work", "department"}),
Values: jtdinfer.NewHintSet().Add([]string{"values"}),
Discriminator: jtdinfer.NewHintSet().Add([]string{"discriminator", "-", "type"}),
}
schema := jtdinfer.InferStrings(rows, hints).IntoSchema()
j, _ := json.MarshalIndent(schema, "", " ")
print(string(j))
}