On Tuesday, 9 July 2013 17:08:18 UTC-4, [email protected] wrote:
I want to be able to normalize the data in a map[string]interface{}.

So if I have a type

type A string

I want to be able to convert an instance of A in a map to a string.

So if I have something like m := map[string]interface{}{"a" : A("string

I want to be able to convert it to map[string]interface{}{"a" : "string

m := map[string]interface{}{"a" : A("string field")}
m2 := make(map[string]interface{}{"a" : "string field"})
for k, v := range m {
     m2[k] = string(v)

However, I do not want to use something like fmt.Sprintf("%v", m["a"]),
because I don't want ints or the like converted to strings.

Using reflection I'm able to go through and change each field, but since
the map is map[string]*interface{}*, I can't get the type of m["a"]
(reflect.TypeOf(m["a"]) and reflect.TypeOf(m["a"]).Kind() ==
reflect.Interface ).

Does anyone know how to check if an interface field is either a string or
any kind of (type X string) ?
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 6 | next ›
Discussion Overview
groupgolang-nuts @
postedJul 10, '13 at 2:42a
activeJul 11, '13 at 7:42a



site design / logo © 2023 Grokbase