<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/json
diff options
context:
space:
mode:
Diffstat (limited to 'json')
-rw-r--r--json/write.go4
-rw-r--r--json/write_test.go16
2 files changed, 18 insertions, 2 deletions
diff --git a/json/write.go b/json/write.go
index 334dfc0..3a5a621 100644
--- a/json/write.go
+++ b/json/write.go
@@ -217,7 +217,7 @@ func (writer *JSONWriter) inMapAt(keepLen int, path []walk.PathSegment) bool {
return writer.state == JSONWriterStateInMap
}
- _, isString := writer.path[0].(string)
+ _, isString := writer.path[keepLen].(string)
return isString
}
@@ -230,7 +230,7 @@ func (writer *JSONWriter) inArrayAt(keepLen int, path []walk.PathSegment) bool {
return writer.state == JSONWriterStateInArray
}
- _, isInt := writer.path[0].(int)
+ _, isInt := writer.path[keepLen].(int)
return isInt
}
diff --git a/json/write_test.go b/json/write_test.go
index a0e8c3e..b495d94 100644
--- a/json/write_test.go
+++ b/json/write_test.go
@@ -263,6 +263,22 @@ func TestWrite(t *testing.T) {
},
expected: `[[["a"],[]]]`,
},
+ {
+ values: []walk.Value {
+ walk.ArrayValue {{
+ Index: 0,
+ Value: walk.MapValue {{
+ Key: "a",
+ Value: walk.StringValue("a"),
+ }},
+ }},
+ walk.ArrayValue {{
+ Index: 0,
+ Value: walk.MapValue{},
+ }},
+ },
+ expected: `[{"a":"a"}]`,
+ },
}
for i, test := range tests {