Quantcast
Channel: User Norbert - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Norbert for Unmarshaling nested custom same-type JSON in Go

$
0
0

Given your json, you can do this:

type Envelope struct {    Some     string         `json:"some"`    Nested   json.RawMessage  `json:"nested"`}

json.RawMessage is a rather hidden gem, and more people seem to go for the map[string]interface{}.

Using json.RawMessage will result in the nested json to be represented by this RawMessage, which you then can process again as a normal json (unmarshal it into Envelope).

This is more elegant than the map[string]interface{} approach.


Viewing all articles
Browse latest Browse all 42

Trending Articles