JSON - The Fine Print: Part 3 - Zero vs Missing Values
Ardan Labs Blog on ·
Follow into
Save into
Introduction
In part 1 we took a higher level view on serialization in general and JSON in specific. In part 2 we looked at emitting JSON.
In part 3, we’ll look at an issue you might encounter when consuming JSON, Zero vs NULL field values. To clarify the definition of NULL, this means the absence of value.
So here is the question:
Given a field in a Go struct set to its zero value, how do you know that zero value was set by the user or it’s zero because it was never provided?