Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions sjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]`,
Expand Down