HttpService::JSONEncode does not document the max buffer size allowed for json encoding (50 MB)

The docs do not document the fact that HttpService::JSONEncode does not allow buffers above 50 mb (52428800 bytes) in size. Attempting to do so throws the error invalid buffer size.

This can be quickly verified with the following script (run in studio command bar):

local HttpService = game:GetService('HttpService')
local max_buffer_size = 52_428_800 -- 50 mb

local buffer_max = buffer.create(max_buffer_size)
local buffer_overmax = buffer.create(max_buffer_size + 1)

local success_max = pcall(function() HttpService:JSONEncode(buffer_max) end)
local success_overmax, error_string = pcall(function() HttpService:JSONEncode(buffer_overmax) end)

print(`\n\n52_428_800 byte encode success: {success_max}\n52_428_801 byte encode success: {success_overmax}, err: {error_string}`)

which outputs the following:

52_428_800 byte encode success: true
52_428_801 byte encode success: false, err: invalid buffer size

Page URL: https://create.roblox.com/docs/reference/engine/classes/HttpService?utm_source=studio&utm_content=show_document#JSONEncode

1 Like

Just use CompressBuffer :nerd_face: :nerd_face: :nerd_face:

Thanks a bunch Mauio. I added the buffer limit to the page. Either the limit for tables is much higher, or the compression is that aggressive, but I wasn’t able to bump into it after a bit of testing (and couldn’t find anything in code).

1 Like