go-json-experiment / json

Experimental implementation of a proposed v2 encoding/json package
BSD 3-Clause "New" or "Revised" License
341 stars 11 forks source link

Suggestion: support emitUnpopulated like protojson does #9

Closed JohnRusk closed 9 months ago

JohnRusk commented 1 year ago

Hi,

Occasionally, it's desirable to get a json representation of an object that includes all fields - even those marked with omitempty and which are currently empty. An example would be if you're providing the output to a human reader to show them the structure of the object. In that case, it's nice to include all fields even those that are currently empty.

So, it would be nice if this library included a setting such as emitUnpopulated in MarshalOptions. When true, the omitempty tag would be ignored.

Protojson alread has a similar setting.

dsnet commented 9 months ago

I think this is out-of-scope for the current project. Feel free propose something over at github.com/golang/go. The set of additional features provided by this module are all based on the most popular feature requests on the main issue tracker: https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+encoding%2Fjson+in%3Atitle+sort%3Areactions-%2B1-desc+