jsony icon indicating copy to clipboard operation
jsony copied to clipboard

extend `skipHook` to skip object fields based on values

Open georgelemon opened this issue 1 year ago • 2 comments

tests included

georgelemon avatar Apr 01 '24 12:04 georgelemon

Great idea! I guess an example in the Readme would also be welcome, so that the feature is discoverable (I am not the maintainer)

pietroppeter avatar Apr 01 '24 15:04 pietroppeter

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

georgelemon avatar Apr 02 '24 05:04 georgelemon