-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to parse bigints when using Response.json() function? #34
Comments
Response isn’t a thing in the language - it’d be the job of, in this case, HTML to add support for it. |
I will open an issue at https://github.com/whatwg/fetch which looks like the right spot for this question. Thanks! |
I just tried: JSON.parse(JSON.stringify(JSON.rawJSON(12345678901234567890n)), (k, v) => { console.log({ k, v }); return v; }) and there's no way I can get the original edit never mind, I've just realized the source is different from the returned value ... how bizarre, I should've seen that coming in the reviver. |
JSON.parse(
JSON.stringify(JSON.rawJSON(12345678901234567890n)),
(k, v, c) => { if (typeof v === 'number') return BigInt(c.source); return v; }
) |
@bakkot ... not quite: const reviver = (_, value, context) => (
context && typeof value === 'number' && String(value) !== context.source ?
BigInt(context.source) : value
); |
In many cases, JSON parsing happens indirectly when an application calls
Response.json()
function after fetching JSON payload from a service using the Fetch API.Would it be within the scope of this proposal to enhance
Response.json()
to add support forreviver
option?Or, is the recommendation to use
Response.text()
and then callJSON.parse
directly with a reviver function?Thank you for advancing this proposal! We at Esri are tracking this proposal as part of adding support for big integers to our ArcGIS Online Cloud platform. Not being able to serialize and de-serialize is a blocker at the moment.
The text was updated successfully, but these errors were encountered: