Quantcast
Channel: Unmarshal JSON in JSON in Go - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Unmarshal JSON in JSON in Go

$
0
0

I want to unmarshal a JSON object where one field contains a JSON string into one coherent object. How do I do that in Go?

Example:

Input:

{"foo":1,"bar":"{\\"a\\":\\"Hello\\"}"}

Go type:

type Child struct {    A string `json:"a"`}type Main struct {    Foo int   `json:"foo"`    Bar Child `json:"bar"`}

I guess I'd need to implement a custom UnmarshalJSON implementation on one of the types, but its twisting my head to figure out on which one and how.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>