Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of nested array objects identified with # is not working #81

Open
samybenatt opened this issue Apr 23, 2024 · 0 comments
Open

Update of nested array objects identified with # is not working #81

samybenatt opened this issue Apr 23, 2024 · 0 comments

Comments

@samybenatt
Copy link

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant