Doesn't work with object in array
Closed this issue · 2 comments
eldadts commented
jsonObj := gabs.New()
jsonObj.Set("Test1", "Tag")
jsonObj.ArrayP("Fields")
jsonObj1 := gabs.New()
jsonObj1.Set("Test2", "Tag")
jsonObj.ArrayAppend(jsonObj1, "Fields")
fmt.Println(jsonObj.String())
result:
{"Fields":[{}],"Tag":"Test1"}
expecting:
{"Fields":[{"Tag":"Test2}],"Tag":"Test1"}
Jeffail commented
Hey @xtrimf, when inserting the value of one container to another you need to reference the underlying data rather than the container itself, so line 6 should instead be jsonObj.ArrayAppend(jsonObj1.Data(), "Fields")
.
Got an example here: https://play.golang.org/p/i6ERrTIbZDP
eldadts commented
Oh OK.
Cool!
tnx!