zod icon indicating copy to clipboard operation
zod copied to clipboard

Unparse/serialize

Open mwisnicki opened this issue 1 year ago • 1 comments

It would be nice to use zod schemas to serialize data, effectively doing the inverse of parse method.

All transforms would have to be reversed and optionally fields with default values should be omitted.

One potential problem is that transforms are not bidirectional so that would have to be added first.

mwisnicki avatar Aug 16 '22 20:08 mwisnicki

One potential problem is that transforms are not bidirectional so that would have to be added first

Indeed, this is why Zod doesn't do this and why it probably never will. Limiting transforms to exclusively invertible operations is very not worth it imo.

It's possible this will eventually be added as a new schema type: z.codec(A, B, (arg: A)=>B, (arg: B)=>A). If you have thoughts on the API for that, I'm all ears.

colinhacks avatar Sep 06 '22 04:09 colinhacks

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 05 '22 05:11 stale[bot]