tidwall / pjson

A JSON stream parser for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pjson

GoDoc

A JSON stream parser for Go and (Rust)

Example

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"

Contact

Josh Baker @tidwall

License

pjson source code is available under the MIT License.

About

A JSON stream parser for Go

License:MIT License


Languages

Language:Go 100.0%