Skip to content

bug(encode): omitempty is not following strictly encoding/json definition #695

@bwplotka

Description

@bwplotka

Describe the bug

As discussed on the global omitempty option PR, we noticed go-yaml is implementing omitemptyin a different way than Go std encoding/json which may cause some surprises. Initially we thought omitempty is implemented as omitzero, but in fact go-yaml omitempty is a mix of features from std encoding omitempty and omitzero features (:

Technically, those those two are a distinct separate options e.g. in encoding/json with omitzero being introduced only recently to the std json lib..

The difference is a bit nuanced, but the key difference can be distilled into two main things:

This "bug" is often a feature, because generally what user wants is something close to omitzero. Perhaps this is why gopkg.in/v2 implemented omitempty as such and go-yaml simply took that.

Thoughts? @goccy

Version Variables

  • Go version: 1.24
  • go-yaml's Version: all until now 1.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions