sjson icon indicating copy to clipboard operation
sjson copied to clipboard

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

Open Robert-M-Muench opened this issue 4 years ago • 1 comments

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?

Robert-M-Muench avatar Jan 09 '22 16:01 Robert-M-Muench

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"]]

tidwall avatar Mar 22 '22 16:03 tidwall