Skip to content

Commit 6cb6379

Browse files
committed
Merge pull request #1 from alexzorin/null_and_bool_support
Support boolean and null JSON values
2 parents 50c19eb + 3a32595 commit 6cb6379

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

json-to-go.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function jsonToGo(json, typename)
4242

4343
function parseScope(scope)
4444
{
45-
if (typeof scope === "object")
45+
if (typeof scope === "object" && scope !== null)
4646
{
4747
if (Array.isArray(scope))
4848
{
@@ -104,6 +104,9 @@ function jsonToGo(json, typename)
104104

105105
function goType(val)
106106
{
107+
if (val === null) {
108+
return "interface{}";
109+
}
107110
switch (typeof val)
108111
{
109112
case "string":
@@ -118,6 +121,8 @@ function jsonToGo(json, typename)
118121
}
119122
else
120123
return "float32"
124+
case "boolean":
125+
return "bool";
121126
case "object":
122127
return "struct";
123128
case "array":

0 commit comments

Comments
 (0)