Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active December 21, 2019 13:37
Show Gist options
  • Select an option

  • Save gsscoder/df9f086f21e242787b407cd8e055e193 to your computer and use it in GitHub Desktop.

Select an option

Save gsscoder/df9f086f21e242787b407cd8e055e193 to your computer and use it in GitHub Desktop.
Go program that parses JSON with buger/jsonparser
package main
import (
"fmt"
"github.com/buger/jsonparser"
)
var data = []byte(`
{
"keys": {
"key0": {"this": 10, "that": "hello"},
"key1": {"this": 11, "that": "world"}
}
}`)
func main() {
jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error {
fmt.Printf("Key: '%s'\n Value: '%s'\n Type: %s\n", string(key), string(value), dataType)
return nil
}, "keys", "key0")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment