Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions json-to-struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down