guregu / null

reasonable handling of nullable values
BSD 2-Clause "Simplified" License
1.84k stars 238 forks source link

[Question] Is it possible to have SQL null values treated as null in Go but encode them to zero in JSON? #61

Closed maxiride closed 3 years ago

maxiride commented 3 years ago

From the documentation I understand that types are either fully treated as zero or null values in Go and JSON.

I am trying to understand if I can use null values in Go but have them encoded to zero in JSON.

guregu commented 3 years ago

The zero package types will marshal to zero values in JSON but null in SQL. For example a blank zero.String will be considered null, and JSON marshal as "".

maxiride commented 3 years ago

The zero package types will marshal to zero values in JSON but null in SQL. For example a blank zero.String will be considered null, and JSON marshal as "".

Sorry I must have made confusion in the phrasing but thanks for the clarification!


By the way awesome package!