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

Why (*simplejson.Json).UnmarshalJSON abandon old content in it? #83

Open
HolaYang opened this issue Oct 20, 2019 · 0 comments
Open

Why (*simplejson.Json).UnmarshalJSON abandon old content in it? #83

HolaYang opened this issue Oct 20, 2019 · 0 comments

Comments

@HolaYang
Copy link

HolaYang commented Oct 20, 2019

In Standard Library "encoding/json", do json.Unmarshal(bytes, target) multiple times with different bytes, only duplicate keys will be overwritten by newer one, other keys are always kept.

 var j, _ = simplejson.NewJson([]byte(`{"a":"a"}`))
 j.UnmarshalJSON([]byte(`{"b":"b"}`))
 var b, _ = j.MarshalJSON()
 fmt.Println(string(b)) // {"b": "b"}

 var v = new(V)
 json.Unmarshal([]byte(`{"a":"a"}`), v)
 json.Unmarshal([]byte(`{"b":"b"}`), v)
 b, _ = json.Marshal(v)
 fmt.Println(string(b)) // {"a": "a", "b": "b"}

How about providing a new method like that?

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

No branches or pull requests

1 participant