Closed christoth closed 4 years ago
Would it be possible to set a value to an object/array? So don't escape the string value if it starts with "{" | "[" and ends with "}" | "]".
"{" | "["
"}" | "]"
value, _ := sjson.Set(`{"name":"Andy"}`, "friends", `["Carol","Sara"]') println(value) // Output: // {"name":"Andy","friends":["Carol","Sara"]}
value, _ := sjson.Set(`{"name":"Andy"}`, "meta", `{"gender":"M","age":42}`) println(value) // Output: // {"name":"Andy","meta":{"gender":"M","age":42}}
Or append an object/array to an existing array?
value, _ := sjson.Set(`{"friends":[{"name":"Andy","age": 8},{"name":"Carol","age":7}]}`, "friends.-1", `{"name":"Sara","age":8}`) println(value) // Output: // {"friends":[{"name":"Andy","age": 8},{"name":"Carol","age":7},{"name":"Sara","age":8}]}
Thanks in advance!
I think the SetRaw function might be what you are looking for.
That worked perfectly, thank you!
Would you like me to create a PR to add SetRaw to the readme doc?
Would it be possible to set a value to an object/array? So don't escape the string value if it starts with
"{" | "["
and ends with"}" | "]"
.Or append an object/array to an existing array?
Thanks in advance!