Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save gsscoder/ad8f271e218dbfae1d825eadc73662a1 to your computer and use it in GitHub Desktop.
Go program that parses JSON with tidwall/gjson
package main
import (
"fmt"
"github.com/tidwall/gjson"
)
var data = `
{
"keys": {
"key0": {"this": 10, "that": "hello"},
"key1": {"this": 11, "that": "world"}
}
}`
func main() {
result := gjson.Get(data, "keys")
result.ForEach(func(key, value gjson.Result) bool {
fmt.Printf("%s %s", key.String(), value.String())
return true // keep iterating
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment