TL;DR

Unsurprisingly, encode_json encodes stuff.

Well, Iโ€™m not suddenly become crazy. I mean, I became crazy little by little, but Iโ€™m digressing.

I was curious about whether a JSON-encoded string would still have to be UTF-8 encoded before being printed (and later decoded after having been read as an octet stream).

It turns out itโ€™s not necessary: the JSON-encoded string is already also UTF-8 encoded, so itโ€™s just necessary to print that out to a :raw filehandle.

And of course the contrary applies too: just read the stuff like :raw octets, and let decode_json do the rest.

Nifty!