Update of nested array objects identified with # is not working
samybenatt opened this issue · comments
Hello,
Here is a sample program illustrating the issue:
package main
import "github.com/tidwall/sjson"
const json = `{"object1":{"object2":[{"nested_object1":{"nested_object2":[{"nested2_object1":1},{"nested2_object1":1}]}}]}}`
func main() {
value, _ := sjson.Set(json, "object1.object2.#.nested_object1.nested_object2.#.nested2_object1", 2)
println("updated all nested arrays objects with # identifier: ", value)
value2, _ := sjson.Set(json, "object1.object2.#.nested_object1.nested_object2.0.nested2_object1", 2)
value3, _ := sjson.Set(value2, "object1.object2.#.nested_object1.nested_object2.1.nested2_object1", 2)
println("updated nested arrays with index identifier, one by one: ", value3)
}
Output:
updated all nested arrays objects with # identifier: 2ect1":{"object2":[{"nested_object1":{"nested_object2":[{"nested2_object1":1},{"nested2_object1":1}]}}]}}
updated nested arrays with index identifier, one by one: {"object1":{"object2":[{"nested_object1":{"nested_object2":[{"nested2_object1":2},{"nested2_object1":2}]}}]}}
As we can see, when I try to update the same property of nested array's objects, it is not able to do it
But when I do it one by one, by identifying the index properly, it works
Anything I'm doing wrong ?