Re: [go-nuts] Re: json.number in struct

2020-11-04 Thread Urjit Singh Bhatia
Yeah, iirc JSON doesn't really have a clear distinction between float and 
int because it has to sort of stay parallel to javascript.

Found this link that explains a bit more...
Excerpt: 
```The precise treatment of the “integer” type may depend on the 
implementation of your JSON Schema validator. JavaScript (and thus also 
JSON) does not have distinct types for integers and floating-point values. 
Therefore, JSON Schema can not use type alone to distinguish between 
integers and non-integers. ```
from 
https://json-schema.org/understanding-json-schema/reference/numeric.html#id4

On Monday, November 2, 2020 at 3:36:07 AM UTC-8 Jan Mercl wrote:

> On Mon, Nov 2, 2020 at 12:30 PM irvan hendrik  wrote:
>
> > yes. because when I marshal it to json the number got messed up.
> > when I entered value 10.0 it became 10.
> > If I use json.number it keeps the format 10.0.
>
> Sounds like conflating data and their representation. I'm not a json
> expert, but AFAIK, the sequence of characters `10` and `10.0`
> represent the very same json number.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b6e7cb0e-849f-4d0f-8298-6d27d8752825n%40googlegroups.com.


Re: [go-nuts] Re: json.number in struct

2020-11-02 Thread Jan Mercl
On Mon, Nov 2, 2020 at 12:30 PM irvan hendrik  wrote:

> yes. because when I marshal it to json the number got messed up.
> when I entered value 10.0 it became 10.
> If I use json.number it keeps the format 10.0.

Sounds like conflating data and their representation. I'm not a json
expert, but AFAIK, the sequence of characters `10` and `10.0`
represent the very same json number.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-Un142M6j8FvwV%2BcmhiptQ%3DuPoSznwRuK8LT5UPAdQJYA%40mail.gmail.com.


Re: [go-nuts] Re: json.number in struct

2020-11-02 Thread irvan hendrik
yes. because when I marshal it to json the number got messed up.
when I entered value 10.0 it became 10.
If I use json.number it keeps the format 10.0.

Regards.


On Mon, Nov 2, 2020 at 2:46 PM Brian Candler  wrote:

> Is there a particular reason why you don't just do this?
>
> type Product struct {
> Weight float64
> }
>
> That should serialize to/from JSON just fine.  You can also include
> metadata about how you want it serialized:
>
> type Product struct {
> Weight float64 `json:"weight,omitempty"`
> }
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/07b5217b-2b7e-47e0-8316-fba13d869cado%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEKPugjgkCrsZ8yq-_cTcux3Ls2VUo_NANn1F45-oH826uuu9A%40mail.gmail.com.


[go-nuts] Re: json.number in struct

2020-11-01 Thread Brian Candler
Is there a particular reason why you don't just do this?

type Product struct {
Weight float64
}

That should serialize to/from JSON just fine.  You can also include 
metadata about how you want it serialized:

type Product struct {
Weight float64 `json:"weight,omitempty"`
}


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/07b5217b-2b7e-47e0-8316-fba13d869cado%40googlegroups.com.