logoalt Hacker News

thayne • today at 6:58 PM • 1 reply • view on HN

> You don’t get runtime errors for marshalling pointers to JSON

https://pkg.go.dev/encoding/json/v2#Marshal says otherwise:

> The Go map key must encode as a JSON string, otherwise this results in a SemanticError

> All other Go types (e.g., complex numbers, channels, and functions) have no default representation and result in a SemanticError.

v1 has the same constraints.


Replies

hnlmorg • today at 9:06 PM

> A Go pointer is encoded as a JSON null if nil, otherwise it is the recursively JSON-encoded representation of the underlying value.

The doc you linked to literally proves me right.