diff --git a/README.md b/README.md index 4598424..d34ca72 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,25 @@ value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.2", "Sara") println(value) // Output: -// {"friends":["Andy","Carol","Sara"] +// {"friends":["Andy","Carol","Sara"]} +``` + +Update existing value in array: +```go +value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.1", "Sara") +println(value) + +// Output: +// {"friends":["Andy","Sara"]} +``` + +Update all existing values in array: +```go +value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.#()#", "Sara") +println(value) + +// Output: +// {"friends":["Sara","Sara"]} ``` Append an array value by using the `-1` key in a path: @@ -174,7 +192,7 @@ value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.-1", "Sara") println(value) // Output: -// {"friends":["Andy","Carol","Sara"] +// {"friends":["Andy","Carol","Sara"]} ``` Append an array value that is past the end: @@ -183,7 +201,7 @@ value, _ := sjson.Set(`{"friends":["Andy","Carol"]}`, "friends.4", "Sara") println(value) // Output: -// {"friends":["Andy","Carol",null,null,"Sara"] +// {"friends":["Andy","Carol",null,null,"Sara"]} ``` Delete a value: diff --git a/sjson_test.go b/sjson_test.go index aa3d968..ed54fd0 100644 --- a/sjson_test.go +++ b/sjson_test.go @@ -68,6 +68,7 @@ func TestBasic(t *testing.T) { testRaw(t, setRaw, `[null,true]`, ``, "1", `true`) testRaw(t, setRaw, `[1,null,true]`, `[1]`, "2", `true`) testRaw(t, setRaw, `[1,true,false]`, `[1,null,false]`, "1", `true`) + testRaw(t, setRaw, `[true,true,true]`, `[1,null,false]`, "#()#", `true`) testRaw(t, setRaw, `[1,{"hello":"when","this":[0,null,2]},false]`, `[1,{"hello":"when","this":[0,1,2]},false]`,