Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Robert-M-Muench opened this issue Jan 9, 2022 · 1 comment

Comments

@Robert-M-Muench
Copy link

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
Copy link
Owner

tidwall commented Mar 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants