Skip to content

Instantly share code, notes, and snippets.

@binarin
Created May 17, 2017 14:44
Show Gist options
  • Save binarin/6c017e2831af391b6fdac134d6748986 to your computer and use it in GitHub Desktop.
Save binarin/6c017e2831af391b6fdac134d6748986 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"io"
"os"
"fmt"
)
func main() {
var reader io.Reader
reader, err := os.Open("/home/binarin/tmp/dp")
if err != nil {
fmt.Println("Filed to open")
return
}
decoder := json.NewDecoder(reader)
target := make([]interface{}, 0)
err = decoder.Decode(&target)
if err != nil {
fmt.Println(err)
return
}
os.Mkdir("slices", 0777)
for _, item := range target {
top := item.(map[string]interface{})
ts := top["timestamp"].(string)
out, err := os.Create("slices/" + ts)
if err != nil {
fmt.Printf("Failed to create file: %s\n", err)
return
}
defer out.Close()
enc := json.NewEncoder(out)
enc.Encode(top["snapshot"])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment