gojsonexplode go library to flatten/explode nested JSON.
import (
"fmt"
"github.com/nytlabs/gojsonexplode"
)
func main() {
input := `{"person":{"name":"Joe", "address":{"street":"123 Main St."}}}`
out, err := gojsonexplode.Explodejsonstr(input, ".")
if err != nil {
// handle error
}
fmt.println(out))
}
should print:
{"person.address.street":"123 Main St.","person.name":"Joe"}
JSON arrays are flattned using the parent attribute concatenated with a delimiter and the respective index for each of the elements in the array
{"list":[true, false]}
gets exploded to:
{"list.0": true, "list.1":false}