sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Add support for omitempty in JSON tags

Open abdullah2993 opened this issue 1 year ago • 9 comments

Adds a new configuration option json_tags_omit_empty which adds omitempty to JSON tags.

Closes https://github.com/sqlc-dev/sqlc/issues/1098 Closes https://github.com/sqlc-dev/sqlc/issues/1084

Related To: https://github.com/sqlc-dev/sqlc/discussions/1132 https://github.com/sqlc-dev/sqlc/discussions/1087

abdullah2993 avatar Jan 09 '24 21:01 abdullah2993

What's the progress on this? Is this PR just waiting for a review?

flexagoon avatar Feb 28 '24 14:02 flexagoon

Thoughts on an option for setting omitempty on nullable fields only? Slightly more of a pain to implement since JSONTagName doesn't know the nullability of its field.

gregoryjjb avatar Mar 12 '24 19:03 gregoryjjb

Is there an updated status here? Seems like a good fix

j-houston avatar May 30 '24 16:05 j-houston

I don't know if the quality of the code is good, but this feature looks valuable. Reusing the sqlc-generated structs would be great. If they can be extended in any way via config options like this one, it makes them versitile.

andradei avatar Jun 30 '24 02:06 andradei