Skip to content

Commit d569dba

Browse files
mike-hosseinimholt
authored andcommitted
Fix missing struct name (#52)
1 parent a35c83b commit d569dba

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

json-to-go.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ function jsonToGo(json, typename, flatten = true)
6767
}
6868
}
6969

70+
const slice = flatten && ["struct", "slice"].includes(sliceType)
71+
? `[]${parent}`
72+
: `[]`;
73+
7074
if (flatten && depth >= 2)
71-
appender("[]");
75+
appender(slice);
7276
else
73-
append("[]")
77+
append(slice)
7478
if (sliceType == "struct") {
7579
const allFields = {};
7680

@@ -129,7 +133,7 @@ function jsonToGo(json, typename, flatten = true)
129133
}
130134
}
131135
else {
132-
if (depth >= 2){
136+
if (flatten && depth >= 2){
133137
appender(goType(scope));
134138
}
135139
else {

0 commit comments

Comments
 (0)