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

Field of accessed array element cannot be set to another value #91

Open
geoynomous opened this issue Dec 13, 2020 · 0 comments
Open

Field of accessed array element cannot be set to another value #91

geoynomous opened this issue Dec 13, 2020 · 0 comments

Comments

@geoynomous
Copy link

geoynomous commented Dec 13, 2020

What goes wrong here?

// Create new obj
jsonObj := gabs.New()
// Add array of size 0
jsonObj.ArrayOfSize(0, "array")
// Create an element ...
e := gabs.New()
// ... with a field a and value 11
e.Set(11, "a")
// Add element to array
jsonObj.ArrayAppend(e, "array")

// Now access element
eInArray, _ := jsonObj.ArrayElement(0, "array")

// Print the element in the array
fmt.Println("e before", eInArray.String())
// Change the value to 22
eInArray.Set(22, "a")
// Print the element in the array again
fmt.Println("e after", eInArray.String()) // ERROR: why is a not 22 now?

// Print the whole jsonObc
fmt.Println(jsonObj.String()) // ERROR: why is a not 22 now?

Output is this

e before {"a":11}
e after {"a":11}
{"array":[{"a":11}]}

Edit:

jsonObj.SetP(33, "array.0.a") also does not change the value from 11 to 33

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