KV PUT with metadata - 413 too large

Sometimes when I try to put a KV entry with metadata, the API refuses the PUT complaining that the metadata object is too large. I am aware that the metadata limit is 1024 bytes, but when I convert the metadata object to a JSON string, it’s still under the stated limit (although it’s close).

I’ve found that limiting PUT attempts for JSON-encoded metadata object strings to 930 bytes seems to be the magic number.

I’m wondering if there’s a better way for me to predict metadata overflow. I’d also like to know why there seems to be a discrepancy.