Nicolas Martyanoff on Nostr: Go's encoding/json parser is fundamentally broken: it assumes that all numbers are ...
Go's encoding/json parser is fundamentally broken: it assumes that all numbers are floats (a very common mistake about JSON), meaning that if you decode without a concrete type and re-encode, integers become floats (e.g. {"a":42} -> {"a":42.0}).
The UseNumber() option helps with that, but now you have to deal with a custom json.Number type in all data processing functions.
All they had to do was to check for a '.' character in the token during parsing to identify the type of the number.
Published at
2025-02-19 12:44:51Event JSON
{
"id": "a917801c98f5e107f5ba0020af53da91adb9080992a7049c17785cae520b5c38",
"pubkey": "6d91e7b056ab18986298e04a8b278a5e070a726487fd30a599427c79db9070e9",
"created_at": 1739969091,
"kind": 1,
"tags": [
[
"proxy",
"https://fosstodon.org/users/galdor/statuses/114030614387437554",
"activitypub"
]
],
"content": "Go's encoding/json parser is fundamentally broken: it assumes that all numbers are floats (a very common mistake about JSON), meaning that if you decode without a concrete type and re-encode, integers become floats (e.g. {\"a\":42} -\u003e {\"a\":42.0}).\n\nThe UseNumber() option helps with that, but now you have to deal with a custom json.Number type in all data processing functions.\n\nAll they had to do was to check for a '.' character in the token during parsing to identify the type of the number.",
"sig": "a1428a9c796a942396d2adf238ba7cc31b4be947660223de128605e25ab45ec887ea645c67b2c8d36185d590b708c07b86afbc832969149e3021a06f93ddd784"
}