I have this piece of data:
productID, err := products.Insert(map[string]interface{}{
"Properties": map[string]interface{}{
strconv.Itoa(propertyNameID): map[string]string{
"en": "Jeans Jersey",
"nl": "Broek Jersey",
},
strconv.Itoa(propertyColorID): propertyOptionRedID,
},
"Type": productTypeID,
"Propertyset": propertysetID,
"Active": true,
"EAN13": "1234567890123"})
All the ***ID
variables are of type int
. Sadly when I do a normal marshal:
{
"Active":true,
"EAN13":"1234567890123",
"Properties":{
"2286408386526632249":{
"en":"Jeans Jersey",
"nl":"Broek Jersey"
},
"4750062295175300168":7.908474319828591e+18
},
"Propertyset":8.882218269088507e+18,
"Type":7.185126253999425e+18
}
... the some ints are transformed into float
type to the power.
The Itoa
are still just some tests tho, because the marshaller can't do map[int]interface{}
(lists with index-values as integers). I just don't understand why the int
values get changed to their "display"-value, instead of their pure value.
Update: I tried "Properties" with map[string]int
and just one entry. Still the same result :(
You can marshal an int64 as a string in json to avoid the conversion to a float64 by using the string
tag
type T struct {
Val int64 `json:"val,string"`
}
t := T{Val: math.MaxInt64}
j, _ := json.Marshal(t)
fmt.Println(string(j))
// {"val":"9223372036854775807"}