Unmarshal JSON With Multiple Roots In Go

Image for post
Image for post
Photo by Jeremy Bishop on Unsplash

If you need to handle JSON strings or streams that have multiple JSON roots the Go library does come with this functionality, but it not easily accessible. It takes a bit of fiddling with reflect.

Here is my drop-in version:

Originally published at http://elliot.land on October 5, 2018.

Written by

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓 elliotchance@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store