json5 work

This commit is contained in:
Joe 2026-01-22 22:19:00 -06:00
parent cd63b5c9c0
commit fdd1d145cf
22 changed files with 1977 additions and 90 deletions

View file

@ -1,4 +1,5 @@
local HttpService = game:GetService("HttpService")
local JSON5Decoder = require(script.Parent.Parent.json5.JSON5Decoder)
local stringTemplate = [[
Http.Response {
@ -28,7 +29,13 @@ function Response:isSuccess()
end
function Response:json()
return HttpService:JSONDecode(self.body)
-- Try fast native decode first, fallback to JSON5 for NaN/Infinity
local success, result = pcall(HttpService.JSONDecode, HttpService, self.body)
if success then
return result
end
print("[HTTP Response:json()] Native decode failed, using JSON5 for size:", #self.body)
return JSON5Decoder.Decode(self.body)
end
return Response

View file

@ -2,6 +2,8 @@ local HttpService = game:GetService("HttpService")
local Promise = require(script.Parent.Promise)
local Log = require(script.Parent.Log)
local JSON5Decoder = require(script.Parent.json5.JSON5Decoder)
local JSONEncoder = require(script.Parent.json5.JSONEncoder)
local HttpError = require(script.Error)
local HttpResponse = require(script.Response)
@ -29,15 +31,15 @@ local function performRequest(requestParams)
return HttpService:RequestAsync(requestParams)
end)
if success then
Log.trace("Request {} success, response {:#?}", requestId, response)
local httpResponse = HttpResponse.fromRobloxResponse(response)
if httpResponse:isSuccess() then
resolve(httpResponse)
else
reject(HttpError.fromResponse(httpResponse))
end
if success then
Log.trace("Request {} success, response {:#?}", requestId, response)
local httpResponse = HttpResponse.fromRobloxResponse(response)
if httpResponse:isSuccess() then
resolve(httpResponse)
else
reject(HttpError.fromResponse(httpResponse))
end
else
Log.trace("Request {} failure: {:?}", requestId, response)
reject(HttpError.fromRobloxErrorString(response))
end
@ -61,11 +63,17 @@ function Http.post(url, body)
end
function Http.jsonEncode(object)
return HttpService:JSONEncode(object)
return JSONEncoder.Compact5(object)
end
function Http.jsonDecode(source)
return HttpService:JSONDecode(source)
-- Try fast native decode first, fallback to JSON5 for NaN/Infinity
local success, result = pcall(HttpService.JSONDecode, HttpService, source)
if success then
return result
end
print("[HTTP Response:json()] Native decode failed, using JSON5 for size:", #self.body)
return JSON5Decoder.Decode(source)
end
return Http