Skip to content

tidwall/pjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages