A JSON stream parser for Go and (Rust)
The example below prints all string values from a JSON document.
package main
import "github.com/tidwall/pjson"
func main() {
var json = `
{
"name": {"first": "Tom", "last": "Anderson"},
"age":37,
"children": ["Sara","Alex","Jack"],
"fav.movie": "Deer Hunter",
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
]
}
`
pjson.Parse([]byte(json), 0, func(start, end, info int) int {
if info&(pjson.String|pjson.Value) == pjson.String|pjson.Value {
println(json[start:end])
}
return 1
})
}
// output:
// "Tom"
// "Anderson"
// "Sara"
// "Alex"
// "Jack"
// "Deer Hunter"
// "Dale"
// "Murphy"
// "ig"
// "fb"
// "tw"
// "Roger"
// "Craig"
// "fb"
// "tw"
// "Jane"
// "Murphy"
// "ig"
// "tw"
Josh Baker @tidwall
pjson source code is available under the MIT License.