How to read a json object from stdin? I want to copy and paste a json object into the stdin, read it and unmarshal it. Here is the code:
var input string
_, err := fmt.Scan(&input)
if err != nil {
fmt.Println(err)
continue
}
var record MedicalRecord
if err := json.Unmarshal([]byte(input), &record); err != nil {
log.Println(err)
continue
}
And the errors are printed to console.
> 2018/06/26 00:26:32 invalid character ':' after top-level value
> 2018/06/26 00:26:32 unexpected end of JSON input
> 2018/06/26 00:26:32 invalid character ':' after top-level value
> 2018/06/26 00:26:32 invalid character ',' after top-level value
> 2018/06/26 00:26:32 invalid character ':' after top-level value
> 2018/06/26 00:26:32 invalid character ',' after top-level value
> 2018/06/26 00:26:32 invalid character ':' after top-level value
> 2018/06/26 00:26:32 invalid character ',' after top-level value
> 2018/06/26 00:26:32 invalid character ':' after top-level value
> 2018/06/26 00:26:32 invalid character ',' after top-level value
If I'm not mistaken, Go is reading until it finds ' ' . How can I solve this problem?