Reputation: 20043
Suppose we are debugging some Go code, and somewhere in an external dependency we encounter this line:
return json.Marshal(foo)
We want to set a breakpoint and use IntelliJ's "Evaluate Expression" to inspect the JSON being produced. However, this doesn't work:
json.Marshal(foo)
, we only get to see the byte array.string(json.Marshal(foo))
doesn't work because json.Marshal
returns two values, the byte array and an error.So how can I use "Evaluate Expression" to achieve my goal of just printing the produced JSON string when I'm not able to change the underlying source code?
Upvotes: 0
Views: 449
Reputation: 763
you can print the returned bytes as a string
bytes, err := json.Marshal(foo)
// check error here
fmt.Println(string(bytes))
You can't change the byte slice in the debugger to a string without changing the source code.
Upvotes: 3