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

Comments

Projects
None yet
3 participants
@jordan2175
Copy link

commented Jan 13, 2015

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

This comment has been minimized.

Copy link
Contributor

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 Jan 13, 2015

@jordan2175

This comment has been minimized.

Copy link
Author

commented Jan 13, 2015

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.
You can’t perform that action at this time.