Skip to content

Instantly share code, notes, and snippets.

@sugab
Created November 6, 2018 11:02
Show Gist options
  • Save sugab/2c7cf19ecad3e761b802fe6ab313a59b to your computer and use it in GitHub Desktop.
Save sugab/2c7cf19ecad3e761b802fe6ab313a59b to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"io/ioutil"
)
func readJSON(fileName string, filter func(map[string]interface{}) bool) []map[string]interface{} {
datas := []map[string]interface{}{}
file, _ := ioutil.ReadFile(fileName)
json.Unmarshal(file, &datas)
filteredData := []map[string]interface{}{}
for _, data := range datas {
// Do some filtering
if filter(data) {
filteredData = append(filteredData, data)
}
}
return filteredData
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment