What you have is not a single JSON object but a series of (unrelated) JSON objects. You can't use json.Unmarshal() to unmarshal something that contains multiple (independent) JSON values.
Use json.Decoder to decode multiple JSON values (objects) from a source one-by-one.
For example:
func main() {
f := strings.NewReader(file)
dec := json.NewDecoder(f)
for {
var job struct {
Job string `json:"job"`
}
if err := dec.Decode(&job); err != nil {
if err == io.EOF {
break
}
panic(err)
}
fmt.Printf("Decoded: %+v\n", job)
}
}
const file = `{"job": "developer"}
{"job": "taxi driver"}
{"job": "police"}`
Which outputs (try it on the Go Playground):
Decoded: {Job:developer}
Decoded: {Job:taxi driver}
Decoded: {Job:police}
This solution works even if your JSON objects take up multiple lines in the source file, or if there are multiple JSON objects in the same line.
See related: I was getting output of exec.Command output in the following manner. from that output I want to get data which I needed