diff --git a/json-to-struct.go b/json-to-struct.go index 811ee71..cef5d0d 100644 --- a/json-to-struct.go +++ b/json-to-struct.go @@ -217,15 +217,21 @@ func Generate(input io.Reader, parser Parser, structName, pkgName string, tags [ case map[string]interface{}: result = iresult case []interface{}: - src := fmt.Sprintf("package %s\n\ntype %s %s\n", - pkgName, - structName, + if len(iresult) == 1 { + src := fmt.Sprintf("package %s\n\ntype %s %s\n", + pkgName, + structName, typeForValue(iresult, structName, tags, subStructMap, convertFloats)) - formatted, err := format.Source([]byte(src)) - if err != nil { - err = fmt.Errorf("error formatting: %s, was formatting\n%s", err, src) + formatted, err := format.Source([]byte(src)) + if err != nil { + err = fmt.Errorf("error formatting: %s, was formatting\n%s", err, src) + } + return formatted, err + } else { + result = map[string]interface{}{ + "temp" : iresult, + } } - return formatted, err default: return nil, fmt.Errorf("unexpected type: %T", iresult) }