A little confused about Structs and how to generate JSON with them

So, I implemented a “service” that is actually quite easy: it interfaces with a REST resource and makes HTTP calls, sending and receiving JSON.
I’ve built it as a struct as it seemed at that time like a good idea (99% chance this comes from OOP :slight_smile:

(mostly pseudocode)

My problem is on the update function: I receive a struct that I use to generate the JSON, but it’s an update action on a remote resource, so coming from a Phoenix form it has a lot of keys with empty value, and given that I (I think mistakenly) generate the JSON with named params it triggers an update with data that should be left alone (an empty string is like “DO NOTHING”) but is updated with empty strings (and fails validation).
I know I could just populate the form with the data I already have, but I’m wondering if there’s an easier way, like to clean the struct before generating the JSON.

Do you guys have any suggestion? I know structs are Maps in disguise, but I’d like to know if there’s an idiomatic/smarter way to do this.

TIA,
ngw

The usual way is to just clean empty strings and remove them from the params. There is a plug to do that for you too if you want it on everything in your controller. If I read that right. ^.^