-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
JSON.stringify replacer option #3360
Comments
This is related to #1706 Enabling customizing a JSON serializer is a good feature. We must consider whether it can keep the TypeScript types for RPC mode( I'll leave comments if I have a good idea. |
Just following up to see if any ideas spawned. Generally this seems to be a common ask (usually around dates) based on #1559, #1800, and #1706 I'm currently using the article you pointed out in #1559 - some tweaks were needed due to changes and it generally works but this is a workaround. |
Related: #1096. Not sure why the author closed the original issue as completed. Also not sure about your stance on discussions in closed issues so opening a new one
What is the feature you are proposing?
I think having a custom JSON.stringify option available would be beneficial.
Currently I sometimes have to do either
which introduces overhead since Hono will make another
JSON.stringify
pass internally, orwhich isn't the most ergonomic to type (and also loses typed response)
as workarounds
I'm thinking as an initialization option when initializing the Hono app, we can pass a custom stringifier
that would then be used here:
hono/src/context.ts
Line 829 in bdaaa7f
A possible footgun migth be that the replacer function could change the types, but so could the normal JSON.stringify, e.g.
which a safe number replacer could "fix" by replacing Infinity with
Number.MAX_SAFE_INTEGER
depending on the applicationThe text was updated successfully, but these errors were encountered: