FAQ
When working on json in Go like with "application/json", make sure your
json is in strict coding

{username: "user", password: "pass"} is not strict in Go and decoding will
fail

instead do

{"username" : "user", "password" : "pass"} that is all values must in ""

and use string for struct fields, like

type User struct {
     Username string
     Password string
     LoginCount string
}

using go 1.1.2

--
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

  • Jeremy Wall at Sep 24, 2013 at 3:37 pm

    On Tue, Sep 24, 2013 at 10:27 AM, Felix Zilla wrote:

    When working on json in Go like with "application/json", make sure your
    json is in strict coding

    {username: "user", password: "pass"} is not strict in Go and decoding will
    fail
    If by strict you mean valid json syntax then that is correct. But strict
    seems like a strange word to use.

    The json standard clearly dictates that dict keys must be quoted and not
    bare words. What you have above is not
    json it's is a javascript object literal and the two things are not the
    same despite occasional misunderstandings.

    instead do

    {"username" : "user", "password" : "pass"} that is all values must in ""

    and use string for struct fields, like

    type User struct {
    Username string
    Password string
    LoginCount string
    }

    using go 1.1.2

    --
    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.
  • Martin Angers at Sep 24, 2013 at 3:38 pm
    Actually, JSON *requires* the keys to be strings (with double quotes)
    (http://www.json.org/), so it's not so much "strict" json or not, the first
    example is simply *not* JSON.

    Le mardi 24 septembre 2013 11:27:17 UTC-4, Felix Zilla a écrit :
    When working on json in Go like with "application/json", make sure your
    json is in strict coding

    {username: "user", password: "pass"} is not strict in Go and decoding will
    fail

    instead do

    {"username" : "user", "password" : "pass"} that is all values must in ""

    and use string for struct fields, like

    type User struct {
    Username string
    Password string
    LoginCount string
    }

    using go 1.1.2
    --
    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.
  • Felix Zilla at Sep 24, 2013 at 3:46 pm
    true, but with GO is strict in the idea of Go json.Unmarshal
    On Tuesday, 24 September 2013 15:27:17 UTC, Felix Zilla wrote:

    When working on json in Go like with "application/json", make sure your
    json is in strict coding

    {username: "user", password: "pass"} is not strict in Go and decoding will
    fail

    instead do

    {"username" : "user", "password" : "pass"} that is all values must in ""

    and use string for struct fields, like

    type User struct {
    Username string
    Password string
    LoginCount string
    }

    using go 1.1.2
    --
    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.
  • Jeremy Wall at Sep 24, 2013 at 3:56 pm

    On Tue, Sep 24, 2013 at 10:46 AM, Felix Zilla wrote:

    true, but with GO is strict in the idea of Go json.Unmarshal
    I don't think I follow. Go doesn't decode invalid json. So sending a
    javascript object literal that isn't also valid json will fail.
    It's not strict it's just a json decoder. Some json decoders may also
    decode javascript object literals. That doesn't mean
    they are correct though.

    On Tuesday, 24 September 2013 15:27:17 UTC, Felix Zilla wrote:

    When working on json in Go like with "application/json", make sure your
    json is in strict coding

    {username: "user", password: "pass"} is not strict in Go and decoding
    will fail

    instead do

    {"username" : "user", "password" : "pass"} that is all values must in ""

    and use string for struct fields, like

    type User struct {
    Username string
    Password string
    LoginCount string
    }

    using go 1.1.2
    --
    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.
  • Felix Zilla at Sep 24, 2013 at 4:01 pm
    Jeremy
    What I mean is sending valid json to Go, and is the same thing as you've
    been saying,
    my long talk about it is I've send almost the entire day just because my
    json was
    not valid.
    On Tuesday, 24 September 2013 15:27:17 UTC, Felix Zilla wrote:

    When working on json in Go like with "application/json", make sure your
    json is in strict coding

    {username: "user", password: "pass"} is not strict in Go and decoding will
    fail

    instead do

    {"username" : "user", "password" : "pass"} that is all values must in ""

    and use string for struct fields, like

    type User struct {
    Username string
    Password string
    LoginCount string
    }

    using go 1.1.2
    --
    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.
  • Kees Varekamp at Sep 25, 2013 at 11:19 pm
    I for one would welcome a "allow sloppy json" feature in the json package,
    that would allow for unquoted fieldnames, trailing comma's, and comments.
    It would make it perfect to use it for config files.

    I know there are yaml packages and the like around but the json package is
    very easy to work with and it's always right there in the stdlib.

    I think the xml package allows for less than perfect xml too right?
    On Wednesday, September 25, 2013 4:01:46 AM UTC+12, Felix Zilla wrote:

    Jeremy
    What I mean is sending valid json to Go, and is the same thing as you've
    been saying,
    my long talk about it is I've send almost the entire day just because my
    json was
    not valid.
    On Tuesday, 24 September 2013 15:27:17 UTC, Felix Zilla wrote:

    When working on json in Go like with "application/json", make sure your
    json is in strict coding

    {username: "user", password: "pass"} is not strict in Go and decoding
    will fail

    instead do

    {"username" : "user", "password" : "pass"} that is all values must in ""

    and use string for struct fields, like

    type User struct {
    Username string
    Password string
    LoginCount string
    }

    using go 1.1.2
    --
    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.
  • Edwin Castro at Sep 25, 2013 at 11:32 pm

    On 9/25/13 4:19 PM, Kees Varekamp wrote:
    I think the xml package allows for less than perfect xml too right?
    I hope the answer to this is no. :-(

    --
    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.
  • Kees Varekamp at Sep 25, 2013 at 11:47 pm
    I'm pretty sure it does:

    type Decoder struct {
             // Strict defaults to true, enforcing the requirements
             // of the XML specification.
             // If set to false, the parser allows input containing common
             // mistakes:
             // * If an element is missing an end tag, the parser invents
             // end tags as necessary to keep the return values from Token
             // properly balanced.
             // * In attribute values and character data, unknown or malformed
             // character entities (sequences beginning with &) are left alone.


    On Thursday, September 26, 2013 11:32:13 AM UTC+12, Edwin Castro wrote:

    On 9/25/13 4:19 PM, Kees Varekamp wrote:

    I think the xml package allows for less than perfect xml too right?


    I hope the answer to this is no. :-(
    --
    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.
  • Roger peppe at Sep 26, 2013 at 8:11 am

    On 26 September 2013 00:19, Kees Varekamp wrote:
    I for one would welcome a "allow sloppy json" feature in the json package,
    that would allow for unquoted fieldnames, trailing comma's, and comments. It
    would make it perfect to use it for config files.
    There's http://godoc.org/launchpad.net/rjson, which supports
    the above except for comments (it also supports omitting commas
    at the end of lines, which may be going to far for you, I guess,
    though it makes for a nice looking JSON representation).

    --
    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.
  • Kees Varekamp at Sep 26, 2013 at 9:01 am
    oooh nice - c-style comments would be nice too tho, or would that be a
    bridge too far for you?

    On Thu, Sep 26, 2013 at 8:11 PM, roger peppe wrote:
    On 26 September 2013 00:19, Kees Varekamp wrote:
    I for one would welcome a "allow sloppy json" feature in the json package,
    that would allow for unquoted fieldnames, trailing comma's, and
    comments. It
    would make it perfect to use it for config files.
    There's http://godoc.org/launchpad.net/rjson, which supports
    the above except for comments (it also supports omitting commas
    at the end of lines, which may be going to far for you, I guess,
    though it makes for a nice looking JSON representation).


    --
    Kees Varekamp
    *MROffice Director*
    44 Castleford street, 0604, Auckland, New Zealand
    Phone: +6492821656
    Skype: kees.mroffice
    Web: mro <http://mro-global.com>ffice.org

    *MROffice - Meeting Market Research Needs*

    --
    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.
  • Roger peppe at Sep 26, 2013 at 11:07 am
    I'd kinda be more inclined to implement sh-style comments,
    (that way you get #! for free) but perhaps you have some arguments for C style?

    On 26 September 2013 10:01, Kees Varekamp wrote:
    oooh nice - c-style comments would be nice too tho, or would that be a
    bridge too far for you?

    On Thu, Sep 26, 2013 at 8:11 PM, roger peppe wrote:
    On 26 September 2013 00:19, Kees Varekamp wrote:
    I for one would welcome a "allow sloppy json" feature in the json
    package,
    that would allow for unquoted fieldnames, trailing comma's, and
    comments. It
    would make it perfect to use it for config files.
    There's http://godoc.org/launchpad.net/rjson, which supports
    the above except for comments (it also supports omitting commas
    at the end of lines, which may be going to far for you, I guess,
    though it makes for a nice looking JSON representation).



    --
    Kees Varekamp
    MROffice Director
    44 Castleford street, 0604, Auckland, New Zealand
    Phone: +6492821656
    Skype: kees.mroffice
    Web: mroffice.org

    MROffice - Meeting Market Research Needs
    --
    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.
  • Kees Varekamp at Sep 26, 2013 at 11:14 am
    I dont care either way really - its more js-like that way I suppose

    On Thu, Sep 26, 2013 at 11:07 PM, roger peppe wrote:

    I'd kinda be more inclined to implement sh-style comments,
    (that way you get #! for free) but perhaps you have some arguments for C
    style?

    On 26 September 2013 10:01, Kees Varekamp wrote:
    oooh nice - c-style comments would be nice too tho, or would that be a
    bridge too far for you?

    On Thu, Sep 26, 2013 at 8:11 PM, roger peppe wrote:
    On 26 September 2013 00:19, Kees Varekamp wrote:
    I for one would welcome a "allow sloppy json" feature in the json
    package,
    that would allow for unquoted fieldnames, trailing comma's, and
    comments. It
    would make it perfect to use it for config files.
    There's http://godoc.org/launchpad.net/rjson, which supports
    the above except for comments (it also supports omitting commas
    at the end of lines, which may be going to far for you, I guess,
    though it makes for a nice looking JSON representation).



    --
    Kees Varekamp
    MROffice Director
    44 Castleford street, 0604, Auckland, New Zealand
    Phone: +6492821656
    Skype: kees.mroffice
    Web: mroffice.org

    MROffice - Meeting Market Research Needs


    --
    Kees Varekamp
    *MROffice Director*
    44 Castleford street, 0604, Auckland, New Zealand
    Phone: +6492821656
    Skype: kees.mroffice
    Web: mro <http://mro-global.com>ffice.org

    *MROffice - Meeting Market Research Needs*

    --
    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.
  • Konstantin Khomoutov at Sep 26, 2013 at 11:27 am

    On Thu, 26 Sep 2013 12:07:22 +0100 roger peppe wrote:

    I'd kinda be more inclined to implement sh-style comments,
    (that way you get #! for free) but perhaps you have some arguments
    for C style?
    I'm with Kees on this: JSON has very strong affinity with JS in
    peoples' minds, so, I suppose, if one is told "this package is able to
    parse comments in JSON, most people would think of "//" just
    mechanically.

    --
    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.
  • Philippe Quesnel at Sep 25, 2013 at 11:35 pm
    try this one out : http://www.jslint.com/ !!
    can be useful to find out errors in json
    On Tuesday, 24 September 2013 11:27:17 UTC-4, Felix Zilla wrote:

    When working on json in Go like with "application/json", make sure your
    json is in strict coding

    {username: "user", password: "pass"} is not strict in Go and decoding will
    fail

    instead do

    {"username" : "user", "password" : "pass"} that is all values must in ""

    and use string for struct fields, like

    type User struct {
    Username string
    Password string
    LoginCount string
    }

    using go 1.1.2
    --
    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 3:27p
activeSep 26, '13 at 11:27a
posts15
users8
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase