jsony
jsony copied to clipboard
extend `skipHook` to skip object fields based on values
tests included
Great idea! I guess an example in the Readme would also be welcome, so that the feature is discoverable (I am not the maintainer)
The best use case scenario is when working with APIs. I want to use jsony to serialize/deserialize objects in requests & responses. For example
type
Product = object
id, slug: string # filled by the server
published: bool
title, content: string
When making a POST request, I can't send an object that contains an emptyid field (or slug), because those fields are available in a GET request, so most probably I will get an error from the server. Reusing the same Nim object and stripping fields based on their values would be possible with the runtime skipHook