I'm trying to use tidwall/sjson to modify properties in a json object, but getting the following error:
./prog.go:34:77: syntax error: unexpected {, expecting expression
Here's my code:
package main
import (
"fmt"
"github.com/tidwall/sjson"
)
func main() {
config := `{
"root": {
"obj1Arr": [
{
"obj2": {
"obj3Arr": [
{
"key1": "val1",
"key2": {
"val2": ["a", "b"]
}
},
{
"key3": "val3",
"key4": "val4"
}
]
}
}
]
},
"strExample": "bar",
"boolExample": true,
"floatExample": 12.54
}`
value, _ := sjson.Set(config, "root.obj1Arr.0.obj2.obj3Arr", []interface{}[{"hello":"world"}])
fmt.Println(value)
}
You can reproduce the error with this go playground link. I'm trying to modify the object root.obj1Arr[0].obj2.obj3Arr to simply have a single object inside of it. I'm also trying to work with an unstructured object. How can I fix this error?