Skip to content

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

@tipybara

Description

@tipybara

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions