-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (51 loc) · 1.13 KB
/
main.go
File metadata and controls
57 lines (51 loc) · 1.13 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
package main
import (
"fmt"
"strings"
"github.com/xarantolus/jsonextract"
)
var test = `This text contains the following JSON object from https://httpbin.org/json: {
a: true,
"slideshow": {
"author": "Yours Truly",
"date": "date of publication",
"slides": [
{
"title": "Wake up to WonderWidgets!",
"type": "all"
},
{
"items": [
"Why <em>WonderWidgets</em> are great",
"Who <em>buys</em> WonderWidgets"
],
"title": "Overview",
"type": "all"
}
],
"title": "Sample Slide Show"
}
}
That's it.
The parser could be confused by [ opening { brackets, but it should notice that they shouldn't be included.
{
// Keys without quotes are valid in JavaScript, but not in JSON
key: "value",
num: 295.2,
// Comments are removed while processing
// Mixing normal and quotes keys is possible
"obj": {
"quoted": 325,
unquoted: 'test'
}
}
`
func main() {
err := jsonextract.Reader(strings.NewReader(test), func(b []byte) error {
fmt.Println(string(b))
return nil
})
if err != nil {
panic("reader: " + err.Error())
}
}