tidwall / sjson

Set JSON values very quickly in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I append key value?

glossd opened this issue · comments

What function Set does is always prepends key value to a given json object (not an array).
Is there any way to put it in the end of json?

I would like this too. It's weird to see things out of order in tests and logs. It looks like it might be difficult to determine "end" but maybe prepend in front of another path? Something like
func SetAfter(json, path string, value interface{}, basePath string) (string, error) {...}
where basePath becomes the "root" for prepending.

I agree. I just pushed an update that now appends new keys.

It changes the behavior of the existing Set function, so you shouldn't need to change anything on your side.