FAQ
Hi!

Please, take a look: http://play.golang.org/p/B-gZoo3cTB

Is there a way to have big ints as ints after unmarshaling json?

Best Regards,
Nick


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

  • Ck at Aug 23, 2013 at 1:15 am

    <mikalai.sauchanka@...> writes:



    Hi!
    Please, take a look: http://play.golang.org/p/B-gZoo3cTB

    Is there a way to have big ints as ints after unmarshaling json?

    Best Regards,
    Nick




    Checked it! I have to say that integer marshalled by json will be get
    float64 after unmarshalled. You should convert it to any type of integer if
    you wish.
    On the another way, you can see here, https://github.com/bitly/go-simplejson



    --
    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.
  • Stephen Gutekanst at Aug 23, 2013 at 1:24 am
    Nick,

    JSON (JavaScript Object Notation), for clarification, uses Javascript
    syntax and definitions. JavaScript only supports 64-bit floating point
    numbers.

    You'll need to convert them back to other datatypes as you deem necessary.
    But you'll need to be aware that you still can only use up to the precision
    of an 64-bit floating point number.

    If this is a deal-breaker for you, you might look into BSON which supports
    some other numerical data types.

    Stephen
    On Thursday, August 22, 2013 8:54:42 AM UTC-7, mikalai....@gmail.com wrote:

    Hi!

    Please, take a look: http://play.golang.org/p/B-gZoo3cTB

    Is there a way to have big ints as ints after unmarshaling json?

    Best Regards,
    Nick

    --
    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.
  • Jeff Hodges at Aug 23, 2013 at 3:18 am
    Actually, it's worse: JSON only supports integers up to (2^55)-1.
    Javascript, by spec and implementation, stores all numbers as doubles and
    the JSON spec follows it.
    On Thursday, August 22, 2013 6:24:42 PM UTC-7, Stephen Gutekanst wrote:

    Nick,

    JSON (JavaScript Object Notation), for clarification, uses Javascript
    syntax and definitions. JavaScript only supports 64-bit floating point
    numbers.

    You'll need to convert them back to other datatypes as you deem necessary.
    But you'll need to be aware that you still can only use up to the precision
    of an 64-bit floating point number.

    If this is a deal-breaker for you, you might look into BSON which supports
    some other numerical data types.

    Stephen

    On Thursday, August 22, 2013 8:54:42 AM UTC-7, mikalai....@gmail.comwrote:
    Hi!

    Please, take a look: http://play.golang.org/p/B-gZoo3cTB

    Is there a way to have big ints as ints after unmarshaling json?

    Best Regards,
    Nick

    --
    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.
  • Kevin Gillette at Aug 26, 2013 at 2:56 am

    On Thursday, August 22, 2013 9:18:49 PM UTC-6, Jeff Hodges wrote:

    Actually, it's worse: JSON only supports integers up to (2^55)-1.
    Javascript, by spec and implementation, stores all numbers as doubles and
    the JSON spec follows it.
    I see no part of http://www.ietf.org/rfc/rfc4627.txt that indicates that
    the JSON *specification* in any way limits the range of numbers, nor does
    it mention that semantics are adopted from ECMAScript. It does say, "An
    implementation may set limits on the range of numbers," though that cannot
    be used to infer that "JSON supports" something only to a restricted extent.

    --
    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.
  • Matthew Kane at Aug 23, 2013 at 1:55 am
    If you unmarshal into a map[string]int: http://play.golang.org/p/sa-NJuAvOD

    Obviously this won't work if you have anything besides numbers.

    If you unmarshal into a struct: http://play.golang.org/p/jWBLztNDZg

    If you use a json.Decoder, you can tell it to unmarshal numeric
    literals into a json.Number, which can then give you back an integer:
    http://play.golang.org/p/eB0XGRwIKH
    On Thu, Aug 22, 2013 at 11:54 AM, wrote:
    Hi!

    Please, take a look: http://play.golang.org/p/B-gZoo3cTB

    Is there a way to have big ints as ints after unmarshaling json?

    Best Regards,
    Nick


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


    --
    matt kane
    twitter: the_real_mkb / nynexrepublic
    http://hydrogenproject.com

    --
    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 Aug 27, 2013 at 1:12 pm
    Two solutions. One is to unmarshal into a known type.
    For instance (replace *big.Int by int64 or int as appropriate there).
    http://play.golang.org/p/_6FJJfvuHg

    Another solution, useful when you don't know the expected types in
    advance, is to use json.Number: http://play.golang.org/p/W4fKXZTkNG
    (You'll need to decide how to parse the Number after you've
    got it).


    On 22 August 2013 16:54, wrote:
    Hi!

    Please, take a look: http://play.golang.org/p/B-gZoo3cTB

    Is there a way to have big ints as ints after unmarshaling json?

    Best Regards,
    Nick


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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 22, '13 at 11:29p
activeAug 27, '13 at 1:12p
posts7
users7
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase