Json marshalling a map into json object

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

  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.

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:

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.


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

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