gabs icon indicating copy to clipboard operation
gabs copied to clipboard

Field of accessed array element cannot be set to another value

Open geoynomous opened this issue 5 years ago • 0 comments

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

geoynomous avatar Dec 13 '20 18:12 geoynomous