Nicolas Martyanoff on Nostr: I just got bit by a common bug in #Go. encoding/json accepts the null JSON value for ...
I just got bit by a common bug in #Go. encoding/json accepts the null JSON value for a slice. As a result, [] is decoded to an empty slice and null to a nil slice. And while both can be used as a zero-length slice, only one of them will be considered equal to nil. Inconsistent.
Published at
2024-02-12 09:54:33Event JSON
{
"id": "f745a64cdda0caeed157494345cc8e86abbaa3dd394054e7d776464a7aff60b7",
"pubkey": "f320bdda416aa99f2ae0949dca56c3bf58a9815c9de7ba950ad1fa568da2b816",
"created_at": 1707731673,
"kind": 1,
"tags": [
[
"t",
"go"
],
[
"proxy",
"https://emacs.ch/users/galdor/statuses/111917902930133879",
"activitypub"
]
],
"content": "I just got bit by a common bug in #Go. encoding/json accepts the null JSON value for a slice. As a result, [] is decoded to an empty slice and null to a nil slice. And while both can be used as a zero-length slice, only one of them will be considered equal to nil. Inconsistent.",
"sig": "d94b51f32a98bd48f62d9a554dc3e0b6b2c0d10937955e3ea2d09a49336d3b42bb78898b95d01c1da31dcf53978d8bea58450b24b2b0f094c468be5b70672786"
}