Skip to content

Commit 2b15550

Browse files
Parameter to omitempty for all fields (#112)
* Omitempty setting jlord/sheetsee.js#26 * Omitempty setting #105
1 parent 825f3da commit 2b15550

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

json-to-go.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
A simple utility to translate JSON into a Go type definition.
88
*/
99

10-
function jsonToGo(json, typename, flatten = true, example = false)
10+
function jsonToGo(json, typename, flatten = true, example = false, allOmitempty = false)
1111
{
1212
let data;
1313
let scope;
@@ -199,7 +199,7 @@ function jsonToGo(json, typename, flatten = true, example = false)
199199
parent = typename
200200
parseScope(scope[keys[i]], depth);
201201
appender(' `json:"'+keyname);
202-
if (omitempty && omitempty[keys[i]] === true)
202+
if (allOmitempty || (omitempty && omitempty[keys[i]] === true))
203203
{
204204
appender(',omitempty');
205205
}
@@ -223,7 +223,7 @@ function jsonToGo(json, typename, flatten = true, example = false)
223223
parent = typename
224224
parseScope(scope[keys[i]], depth);
225225
append(' `json:"'+keyname);
226-
if (omitempty && omitempty[keys[i]] === true)
226+
if (allOmitempty || (omitempty && omitempty[keys[i]] === true))
227227
{
228228
append(',omitempty');
229229
}

0 commit comments

Comments
 (0)