Reputation: 364
Golang json.Unmarshal throws error for newline character. Go Playground
How to unmarshal data if string contains newline?
Upvotes: 1
Views: 11749
Reputation: 1058
Simply escaping the newline character should do the trick:
var val []byte = []byte(`"{\"channel\":\"buupr\\niya\",\"name\":\"john\", \"msg\":\"doe\"}"`)
The output for the above:
{"channel":"buupr\niya","name":"john", "msg":"doe"}
Since you're attempting to pass a raw string literal here, you will need to be able to represent the JSON in string form, which requires you to escape the newline character.
Upvotes: 3