-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonextract.go
46 lines (37 loc) · 861 Bytes
/
jsonextract.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
// Package jsonextract is a library for extracting any valid JSONs from given source
package jsonextract
import (
"io"
"os"
)
// FromString extract JSONs from string
func FromString(str string) ([]*JSON, error) {
r := readFromString(str)
return parseAll(r)
}
// FromBytes extract JSONs from bytes
func FromBytes(byts []byte) ([]*JSON, error) {
r := readFromBytes(byts)
return parseAll(r)
}
// FromReader extract JSONs from reader io.Reader
func FromReader(reader io.Reader) ([]*JSON, error) {
r, err := readFromReader(reader)
if err != nil {
return nil, err
}
return parseAll(r)
}
// FromFile extract JSONs from file in path
func FromFile(path string) ([]*JSON, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
r, err := readFromReader(f)
if err != nil {
return nil, err
}
return parseAll(r)
}