FAQ
Hi,

http://play.golang.org/p/cS1K_nGoI5

I'm trying to use the above program but I don't quite understand why part
of if isn't working - relative noob :)

The aim is to use json.Marshal to get a json string representation, but it
needs to have the lowercase var names, protocol, domain, etc of the
Referrer struct in the json string.

Doing the .Marshal call produces and empty Referrer, which seems to be due
to the lowercase var names in the Referrer type - which I know are non
exportable, but didn't think that would happen on a struct.

Is there any way of getting these lower case names in to the json string?

Thanks in advance,
Mat



--
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 11:28 am
    Use struct tags to annotate the members of your struct to make them
    confirm to the required JSON output.

    On Tue, Sep 24, 2013 at 9:26 PM, Mat Evans wrote:
    Hi,

    http://play.golang.org/p/cS1K_nGoI5

    I'm trying to use the above program but I don't quite understand why part of
    if isn't working - relative noob :)

    The aim is to use json.Marshal to get a json string representation, but it
    needs to have the lowercase var names, protocol, domain, etc of the Referrer
    struct in the json string.

    Doing the .Marshal call produces and empty Referrer, which seems to be due
    to the lowercase var names in the Referrer type - which I know are non
    exportable, but didn't think that would happen on a struct.

    Is there any way of getting these lower case names in to the json string?

    Thanks in advance,
    Mat



    --
    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.
  • Karan Misra at Sep 24, 2013 at 11:33 am
    Just use tags to instruct the json.Marshal to use lowercase names for the
    generated JSON: http://golang.org/pkg/encoding/json/#Marshal

    http://play.golang.org/p/cgPd_PTBtU
    On Tuesday, September 24, 2013 4:56:15 PM UTC+5:30, Mat Evans wrote:

    Hi,

    http://play.golang.org/p/cS1K_nGoI5

    I'm trying to use the above program but I don't quite understand why part
    of if isn't working - relative noob :)

    The aim is to use json.Marshal to get a json string representation, but it
    needs to have the lowercase var names, protocol, domain, etc of the
    Referrer struct in the json string.

    Doing the .Marshal call produces and empty Referrer, which seems to be due
    to the lowercase var names in the Referrer type - which I know are non
    exportable, but didn't think that would happen on a struct.

    Is there any way of getting these lower case names in to the json string?

    Thanks in advance,
    Mat


    --
    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.
  • Mat Evans at Sep 24, 2013 at 11:39 am
    Thanks both of you :D

    Worked like a charm.

    Full answer
    http://play.golang.org/p/aYnsO1JfXm
    On Tuesday, 24 September 2013 12:33:09 UTC+1, Karan Misra wrote:

    Just use tags to instruct the json.Marshal to use lowercase names for the
    generated JSON: http://golang.org/pkg/encoding/json/#Marshal

    http://play.golang.org/p/cgPd_PTBtU
    On Tuesday, September 24, 2013 4:56:15 PM UTC+5:30, Mat Evans wrote:

    Hi,

    http://play.golang.org/p/cS1K_nGoI5

    I'm trying to use the above program but I don't quite understand why part
    of if isn't working - relative noob :)

    The aim is to use json.Marshal to get a json string representation, but
    it needs to have the lowercase var names, protocol, domain, etc of the
    Referrer struct in the json string.

    Doing the .Marshal call produces and empty Referrer, which seems to be
    due to the lowercase var names in the Referrer type - which I know are non
    exportable, but didn't think that would happen on a struct.

    Is there any way of getting these lower case names in to the json string?

    Thanks in advance,
    Mat


    --
    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.
  • Karan Misra at Sep 24, 2013 at 12:23 pm
    Welcome :)
    On Tuesday, September 24, 2013 5:09:35 PM UTC+5:30, Mat Evans wrote:

    Thanks both of you :D

    Worked like a charm.

    Full answer
    http://play.golang.org/p/aYnsO1JfXm
    On Tuesday, 24 September 2013 12:33:09 UTC+1, Karan Misra wrote:

    Just use tags to instruct the json.Marshal to use lowercase names for the
    generated JSON: http://golang.org/pkg/encoding/json/#Marshal

    http://play.golang.org/p/cgPd_PTBtU
    On Tuesday, September 24, 2013 4:56:15 PM UTC+5:30, Mat Evans wrote:

    Hi,

    http://play.golang.org/p/cS1K_nGoI5

    I'm trying to use the above program but I don't quite understand why
    part of if isn't working - relative noob :)

    The aim is to use json.Marshal to get a json string representation, but
    it needs to have the lowercase var names, protocol, domain, etc of the
    Referrer struct in the json string.

    Doing the .Marshal call produces and empty Referrer, which seems to be
    due to the lowercase var names in the Referrer type - which I know are non
    exportable, but didn't think that would happen on a struct.

    Is there any way of getting these lower case names in to the json
    string?

    Thanks in advance,
    Mat


    --
    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.
  • Mat Evans at Sep 24, 2013 at 2:59 pm
    Thanks! :)
    On Tuesday, 24 September 2013 13:23:31 UTC+1, Karan Misra wrote:

    Welcome :)
    On Tuesday, September 24, 2013 5:09:35 PM UTC+5:30, Mat Evans wrote:

    Thanks both of you :D

    Worked like a charm.

    Full answer
    http://play.golang.org/p/aYnsO1JfXm
    On Tuesday, 24 September 2013 12:33:09 UTC+1, Karan Misra wrote:

    Just use tags to instruct the json.Marshal to use lowercase names for
    the generated JSON: http://golang.org/pkg/encoding/json/#Marshal

    http://play.golang.org/p/cgPd_PTBtU
    On Tuesday, September 24, 2013 4:56:15 PM UTC+5:30, Mat Evans wrote:

    Hi,

    http://play.golang.org/p/cS1K_nGoI5

    I'm trying to use the above program but I don't quite understand why
    part of if isn't working - relative noob :)

    The aim is to use json.Marshal to get a json string representation, but
    it needs to have the lowercase var names, protocol, domain, etc of the
    Referrer struct in the json string.

    Doing the .Marshal call produces and empty Referrer, which seems to be
    due to the lowercase var names in the Referrer type - which I know are non
    exportable, but didn't think that would happen on a struct.

    Is there any way of getting these lower case names in to the json
    string?

    Thanks in advance,
    Mat


    --
    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 11:26a
activeSep 24, '13 at 2:59p
posts6
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase