Currently I'm using the following code to convert nested json into flattened 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)
}
This is the output: {"person.address.street":"123 Main St.","person.name":"Joe"}
After some processing, now I want to restore this data into normal nested json, but I'm unable to do so.
My closest guess is usage of nested maps, but I don't know how to create nested map with N levels.
EDIT: Reason why I need this: I'm storing data in Redis, and if I store json into Redis then I can't search for keys, that's why I convert keys into key1:key2:key3: some_value