FAQ
is there any plans to hide empty structs from json output?

outputting

type Actor struct {
Name string `bson:"name,omitempty" json:"name,omitempty"`
Account Account `bson:"account,omitempty" json:"account,omitempty"`
}
type Account struct {
HomePage string `bson:"homePage,omitempty" json:"homePage,omitempty"`
Name string `bson:"name,omitempty" json:"name,omitempty"`
}

shows

"actor": {
             "account": {},
             "mbox": "mailto:s@s.com",
             "objectType": "Agent"
         }

if account is empty, can't omitempty apply to struct?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Dave Cheney at Sep 24, 2013 at 2:56 am
    What happens if you define it like this ?

    type Actor struct {
           Name string ...
           Account *Account ...
    }
    On Tue, Sep 24, 2013 at 12:53 PM, Tobias Contreras wrote:
    is there any plans to hide empty structs from json output?

    outputting

    type Actor struct {
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    Account Account `bson:"account,omitempty" json:"account,omitempty"`
    }
    type Account struct {
    HomePage string `bson:"homePage,omitempty" json:"homePage,omitempty"`
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    }

    shows

    "actor": {
    "account": {},
    "mbox": "mailto:s@s.com",
    "objectType": "Agent"
    }

    if account is empty, can't omitempty apply to struct?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Tobias Contreras at Sep 24, 2013 at 2:58 am
    Nice!

    yup that did it
    On Monday, September 23, 2013 8:56:41 PM UTC-6, Dave Cheney wrote:

    What happens if you define it like this ?

    type Actor struct {
    Name string ...
    Account *Account ...
    }
    On Tue, Sep 24, 2013 at 12:53 PM, Tobias Contreras wrote:
    is there any plans to hide empty structs from json output?

    outputting

    type Actor struct {
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    Account Account `bson:"account,omitempty" json:"account,omitempty"`
    }
    type Account struct {
    HomePage string `bson:"homePage,omitempty" json:"homePage,omitempty"`
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    }

    shows

    "actor": {
    "account": {},
    "mbox": "mailto:s...@s.com <javascript:>",
    "objectType": "Agent"
    }

    if account is empty, can't omitempty apply to struct?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dave Cheney at Sep 24, 2013 at 2:59 am
    Empty is a difficult concept for value types.
    On Tue, Sep 24, 2013 at 12:58 PM, Tobias Contreras wrote:
    Nice!

    yup that did it

    On Monday, September 23, 2013 8:56:41 PM UTC-6, Dave Cheney wrote:

    What happens if you define it like this ?

    type Actor struct {
    Name string ...
    Account *Account ...
    }

    On Tue, Sep 24, 2013 at 12:53 PM, Tobias Contreras <tobi...@gmail.com>
    wrote:
    is there any plans to hide empty structs from json output?

    outputting

    type Actor struct {
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    Account Account `bson:"account,omitempty" json:"account,omitempty"`
    }
    type Account struct {
    HomePage string `bson:"homePage,omitempty" json:"homePage,omitempty"`
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    }

    shows

    "actor": {
    "account": {},
    "mbox": "mailto:s...@s.com",
    "objectType": "Agent"
    }

    if account is empty, can't omitempty apply to struct?

    --
    You received this message because you are subscribed to the Google
    Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an
    email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Tobias Contreras at Sep 24, 2013 at 3:03 am
    ya, but of course an empty pointer is clear, good call
    On Monday, September 23, 2013 8:59:55 PM UTC-6, Dave Cheney wrote:

    Empty is a difficult concept for value types.
    On Tue, Sep 24, 2013 at 12:58 PM, Tobias Contreras wrote:
    Nice!

    yup that did it

    On Monday, September 23, 2013 8:56:41 PM UTC-6, Dave Cheney wrote:

    What happens if you define it like this ?

    type Actor struct {
    Name string ...
    Account *Account ...
    }

    On Tue, Sep 24, 2013 at 12:53 PM, Tobias Contreras <tobi...@gmail.com>
    wrote:
    is there any plans to hide empty structs from json output?

    outputting

    type Actor struct {
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    Account Account `bson:"account,omitempty"
    json:"account,omitempty"`
    }
    type Account struct {
    HomePage string `bson:"homePage,omitempty" json:"homePage,omitempty"`
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    }

    shows

    "actor": {
    "account": {},
    "mbox": "mailto:s...@s.com",
    "objectType": "Agent"
    }

    if account is empty, can't omitempty apply to struct?

    --
    You received this message because you are subscribed to the Google
    Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it,
    send
    an
    email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Gustavo Niemeyer at Sep 24, 2013 at 4:00 am
    mgo/bson defines an empty struct value as a struct that contains empty
    fields. Feels reasonable in practice.
    On Mon, Sep 23, 2013 at 11:59 PM, Dave Cheney wrote:
    Empty is a difficult concept for value types.
    On Tue, Sep 24, 2013 at 12:58 PM, Tobias Contreras wrote:
    Nice!

    yup that did it

    On Monday, September 23, 2013 8:56:41 PM UTC-6, Dave Cheney wrote:

    What happens if you define it like this ?

    type Actor struct {
    Name string ...
    Account *Account ...
    }

    On Tue, Sep 24, 2013 at 12:53 PM, Tobias Contreras <tobi...@gmail.com>
    wrote:
    is there any plans to hide empty structs from json output?

    outputting

    type Actor struct {
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    Account Account `bson:"account,omitempty" json:"account,omitempty"`
    }
    type Account struct {
    HomePage string `bson:"homePage,omitempty" json:"homePage,omitempty"`
    Name string `bson:"name,omitempty" json:"name,omitempty"`
    }

    shows

    "actor": {
    "account": {},
    "mbox": "mailto:s...@s.com",
    "objectType": "Agent"
    }

    if account is empty, can't omitempty apply to struct?

    --
    You received this message because you are subscribed to the Google
    Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an
    email to golang-nuts...@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.


    --

    gustavo @ http://niemeyer.net

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 24, '13 at 2:53a
activeSep 24, '13 at 4:00a
posts6
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase