Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: marshal does not obey omitempty for empty structures #9585

Closed
jordan2175 opened this issue Jan 13, 2015 · 2 comments
Closed

Comments

@jordan2175
Copy link

Given this code

https://play.golang.org/p/9Y92Vqf8Bb

you will see that I have not specified in the raw JSON data any data for the validTimePosition, however, when you run the marshal process it shows up, as illustrated below. I would expect that it would not show up at all, if it is empty.

{
"stixPackage": {
"version": "1.1.1",
"validTimePosition": {}
}
}

@adg
Copy link
Contributor

adg commented Jan 13, 2015

A struct value cannot be 'empty', so it cannot be omitted. You need to use a pointer to a struct:

https://play.golang.org/p/w4s_S-nUKw

@adg adg closed this as completed Jan 13, 2015
@jordan2175
Copy link
Author

Thanks....

@mikioh mikioh changed the title json marshal does not obey omitempty for empty structures encding/json: marshal does not obey omitempty for empty structures Jan 13, 2015
@mikioh mikioh changed the title encding/json: marshal does not obey omitempty for empty structures encoding/json: marshal does not obey omitempty for empty structures Jan 13, 2015
@golang golang locked and limited conversation to collaborators Jan 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants