I am writing a test where I want to compare the result of json.Marshal with a static json string:
var json = []byte(`{ "foo": "bar" }`)
As a result, json.Marshal has no \n , \t and spaces, which I thought I could easily do:
bytes.Trim(json, " \n\t")
to remove all of these characters. However, unfortunately, this does not work. I could write a custom trim function and use bytes.TrimFunc , but it seems complicated to me.
What else can I do to make the json string βcompressedβ with less code?
Best, Bo
json go
bodokaiser
source share