I have a JSON file called example.json
that looks like:
{
"name": "example",
"type": "record"
}
I also have a variable representing the above as a "string":
const example = `{
"name": "example",
"type": "record",
}`
I am trying to understand why reading the contents of the JSON file into bytes is different from reading the contents of the example
variable. My code is as follows:
bytesJSON, err := ioutil.ReadFile("example.json")
if err != nil {
fmt.Println(err)
}
bytesVar, err := json.Marshal(example)
if err != nil {
fmt.Println(err)
}
Both are of the type []uint8
, but look very different. Any ideas on why? And how I can make sure that they are always the same?
EDIT: Even using bytesVar := []byte(example)
results in the same issue.
EDIT:
bytesJSON
looks like:
[123 10 32 32 32 32 34 110 97 109 101 34 58 32 34 101 120 97 109 112 108 101 34 44 10 32 32 32 32 34 116 121 112 101 34 58 32 34 114 101 99 111 114 100 34 10 125]
bytesVar
looks like:
[34 112 117 98 115 117 98 95 101 120 97 109 112 108 101 95 116 111 112 105 99 34]
when printed to stdout
.