You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to parse JSON which has some known/expected fields and some uknown.
What did you expect to see?
Single-pass parsiing of both known and unknown fields.
What did you see instead?
Existing approaches all have downsides. It seems that with standard encoding/json package the best approach is to parse JSON twice, once with the struct with known fields, and once into map[string]interface{}. I find this ugly, redundant, and slow. I would propose to use symbol + to mark a field into which unknown fields should go. So struct could be defined like:
type Message struct {
Name string `json:"name"`
Type string `json:"type"`
Skip string `json:"-"`
Extra map[string]interface{} `json:"+"`
}
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to parse JSON which has some known/expected fields and some uknown.
What did you expect to see?
Single-pass parsiing of both known and unknown fields.
What did you see instead?
Existing approaches all have downsides. It seems that with standard
encoding/json
package the best approach is to parse JSON twice, once with the struct with known fields, and once intomap[string]interface{}
. I find this ugly, redundant, and slow. I would propose to use symbol+
to mark a field into which unknown fields should go. So struct could be defined like:The text was updated successfully, but these errors were encountered: