Json marshalling a map into json object


(Taalhach) #1

how to Marshal a map of float64 type e.g ( map[float64] []interface ) into json object ?
according to json.marshal() documentation map’s keys must be either string or integer i tried to marshal map[float64] string maps into json which gave me error of "type unsupported"
Thanks in advance


(Norbert Melzer) #2
  1. Try not to do this. Always remember, 10 * n is not necessarily equal to n + n + n + n + n + n + n + n + n + n.
  2. If you really have to stick to float keys, stringify them first.

(Taalhach) #3

stingify is a better option actually it is needed in my project to encode a map which is map[ float64 ][ ]data_structure
Thanks btw for your response :slight_smile:


(Norbert Melzer) #4

As I said, you shouldn’t do this.

Find another way to encode your data. If you keep the float you will regret that decission in the future.


(Taalhach) #5

ok i will look into other encoding and thanks for alarming me at the begging :wink:


(system) #6

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.