diff --git a/sjson.go b/sjson.go index 797469b..7f1d358 100644 --- a/sjson.go +++ b/sjson.go @@ -128,7 +128,7 @@ func appendBuild(buf []byte, array bool, paths []pathResult, raw string, } if len(paths) > 1 { n, numeric := atoui(paths[1]) - if numeric { + if numeric || (!paths[1].force && paths[1].part == "-1") { buf = append(buf, '[') buf = appendRepeat(buf, "null,", n) buf = appendBuild(buf, true, paths[1:], raw, stringify) diff --git a/sjson_test.go b/sjson_test.go index b0983cd..a7a8f7e 100644 --- a/sjson_test.go +++ b/sjson_test.go @@ -141,6 +141,7 @@ func TestBasic(t *testing.T) { testRaw(t, setString, `["1234.5"]`, ``, `0`, "1234.5") testRaw(t, setBool, `[true]`, ``, `0`, true) testRaw(t, setBool, `[null]`, ``, `0`, nil) + testRaw(t, setString, `{"arr":[1]}`, ``, `arr.-1`, 1) } func TestDelete(t *testing.T) {