tidwall / sjson

Set JSON values very quickly in Go
MIT License
2.4k stars 165 forks source link

Appending an array entry retrieved from gjson selector result => double arrification #54

Open Robert-M-Muench opened 2 years ago

Robert-M-Muench commented 2 years ago
dest := "[]"
r := gjson.Get(source, "[a, b]"
dest = sjson.Set(dest, ".-1", r.String())

r is something like ["a_value","b_value"] and gets inserted into dest as [[["a_value","b_value"]]]

How can I insert the already arryfied JSON as-is into dest and avoid that it gets arryfied once again?

tidwall commented 2 years ago

Perhaps the SetRaw function is what you are looking for.

r := gjson.Parse(`["a_value","b_value"]`)
dest := "[]"
dest, _ = sjson.SetRaw(dest, "-1", r.String())
println(dest)
[["a_value","b_value"]]