<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Julia Álvarez de Eulate Sainz on Medium]]></title>
        <description><![CDATA[Stories by Julia Álvarez de Eulate Sainz on Medium]]></description>
        <link>https://medium.com/@alvarezjulia?source=rss-d986ba4307c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ue7WkBJWOjSdp-L_egnoJQ.png</url>
            <title>Stories by Julia Álvarez de Eulate Sainz on Medium</title>
            <link>https://medium.com/@alvarezjulia?source=rss-d986ba4307c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 09:28:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alvarezjulia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unmarsahl a Nested JSON in Go]]></title>
            <link>https://medium.com/swlh/unmarsahl-a-nested-json-in-go-c1a953aeda2?source=rss-d986ba4307c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1a953aeda2</guid>
            <category><![CDATA[decoding]]></category>
            <category><![CDATA[go-programming]]></category>
            <category><![CDATA[nested-json]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Julia Álvarez de Eulate Sainz]]></dc:creator>
            <pubDate>Thu, 03 Dec 2020 10:58:14 GMT</pubDate>
            <atom:updated>2020-12-10T16:06:31.088Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unmarsahl Nested JSON in Go</h3><p>It is undeniable that JSON (JavaScript Object Notation) has gained a lot of popularity in the last years. According to Stack Overflow Trends, more questions are asked about it than for any other data interchange format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*75B3UMjoEKflStKHuTwaFA.png" /></figure><p>JSON will often be the best choice when working with data and writing JavaScript code, because it is a natural format of the language. However, there are implementations for many languages, Go being one of them.</p><p>Paraphrasing from the dictionary, decode is:</p><blockquote>to convert something into a human readable form</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nrCi0FIz_yXdVhb2" /><figcaption>Photo by <a href="https://unsplash.com/@centelm?utm_source=medium&amp;utm_medium=referral">Clément Falize</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Go json package</h3><p>The package <a href="https://golang.org/pkg/encoding/json/">json</a> implements encoding and decoding of JSON. For this post we will focus on decoding, specifically nested JSON to a Go struct.</p><h4>Unmarshal or decode?</h4><p><strong>Unmarshal</strong> is the function used for decoding. There is also a method called <strong>Decode </strong>in the json package, where its name is self explanatory of what it does. There is often a misconception between these two.</p><p>Which one should you use? As to every good question, the answer is, it depends. If you are reading values from an input stream, decode will be the right option for you.</p><p>We will be using the unmarshal function in this post. So let’s decode some JSON in Go!</p><h3>Unmarshal</h3><p>Let’s say that we have a list of libraries in JSON. And we want this information organised in a struct like this:</p><pre>type Libraries struct <em>{<br>   </em>LibrariesList <em>[]</em>struct <em>{<br>      </em>Name    string `json:&quot;name&quot;`<br>      City    string `json:&quot;city&quot;`<br>      Country string `json:&quot;country&quot;`<br>      Books   <em>[]</em>struct <em>{<br>         </em>Title        string `json:&quot;title&quot;`<br>         Author       string `json:&quot;author&quot;`<br>         Availability bool   `json:&quot;availability&quot;`<br>      <em>} </em>`json:&quot;books&quot;`<br>   <em>} </em>`json:&quot;libraries&quot;`<br><em>}</em></pre><p>The json values are important since they make it possible for the Go package to map the values correctly. If the value is missing for a specific field, it will be initialised with a zero value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c0702d7a4626ea3e63fe81aed869c23/href">https://medium.com/media/2c0702d7a4626ea3e63fe81aed869c23/href</a></iframe><p>The value of librariesInformation variable is printed out with its field names and the variable will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*6oaTO1xjJWCoHiZfKsPgYw.png" /></figure><p>If you want to check the code you can do so here:</p><p><a href="https://github.com/alvarezjulia/nested-json-struct">alvarezjulia/nested-json-struct</a></p><p>Hope you liked the explanation. Have you used unmarshal in Go before with a nested JSON? Do you think that it is tricky? Is there anything else that I can help you with? Let me know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1a953aeda2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/unmarsahl-a-nested-json-in-go-c1a953aeda2">Unmarsahl a Nested JSON in Go</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>