I have a JSON file of the form:
{
"data": {
"docs": [
{"key00": "val00", "key01": "val01"},
{"key10": "val10", "key11": "val11"}
]
}
}
and I would like to convert it to separate JSON docs:
file0.json
{
{"key00": "val00", "key01": "val01"}
}
file1.json
{
{"key10": "val10", "key11": "val11"}
}
I can enumerate over the array contents using:
j, _ := ioutil.ReadFile(path)
dec, _ := simplejson.NewFromReader(bytes.NewReader(j))
for i,v := range dec.Get("data").Get("docs").MustArray() {
out := simplejson.New()
/* ??? move dec key/value pairs to out ??? */
b, _ := out.EncodePretty()
ioutil.WriteFile(outpath, b, 0777)
}
but I'm not sure how to iterate over the key/value pairs within the array entries. It's a nice, succinct library but there don't appear to be a lot of examples and my golang expertise is currently limited.
Any help would be appreciated.. thanks!