{"id":217,"date":"2026-04-15T09:00:00","date_gmt":"2026-04-15T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=217"},"modified":"2026-10-10T21:20:47","modified_gmt":"2026-10-10T15:50:47","slug":"go-json-encoding-decoding","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/","title":{"rendered":"Go JSON Encoding and Decoding Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go JSON handling lets your program turn structs into text and read that text back into structs. In this post, you will learn Marshal, Unmarshal, struct tags and streaming, with the traps that catch beginners. Each idea comes with a short example that you can run yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This data format maps straight onto structs, so first review <a href=\"https:\/\/smitabharat.com\/blog\/go-structs-beginners-guide\/\">structs and methods in Go<\/a>, where you met struct tags. We will also check every error, just like in <a href=\"https:\/\/smitabharat.com\/blog\/go-error-handling-guide\/\">error handling in Go for beginners<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go JSON Encoding?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It is a plain text format for data, like <code>{\"name\":\"Asha\",\"age\":28}<\/code>. In fact, almost every web API speaks it. In short, encoding means turning a Go value into that text, and decoding means the reverse.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, think of packing a suitcase for a trip. You fold your clothes into a standard shape so they travel well. Then you unpack them at the hotel. Go JSON works the same way with your data, using the <code>encoding\/json<\/code> package.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Struct Tags Control Go JSON<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>type User struct {\n\tName     string   `json:\"name\"`\n\tAge      int      `json:\"age\"`\n\tEmail    string   `json:\"email,omitempty\"`\n\tPassword string   `json:\"-\"`\n\tSkills   &#91;]string `json:\"skills\"`\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the text in backticks tells the package which key name to use. Also, <code>omitempty<\/code> skips a field when it is empty, and <code>\"-\"<\/code> hides it completely. Therefore, it is perfect for secrets like passwords.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Encoding: Struct to Text<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>u := User{Name: \"Asha\", Age: 28, Password: \"secret\", Skills: &#91;]string{\"Go\", \"SQL\"}}\n\ndata, err := json.Marshal(u)\nif err != nil {\n\tfmt.Println(err)\n\treturn\n}\nfmt.Println(string(data))\n\/\/ {\"name\":\"Asha\",\"age\":28,\"skills\":&#91;\"Go\",\"SQL\"]}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>json.Marshal<\/code> returns a byte slice, so convert it with <code>string()<\/code> to print it. Notice that email is missing because it was empty, and the password never appears. Finally, the diagram below shows both directions.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-diagram-1024x640.png\" alt=\"Go JSON diagram showing a struct turned into JSON with Marshal and back with Unmarshal\" class=\"wp-image-219\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Marshal turns a struct into text, and Unmarshal fills a struct from that text, using the tags as key names.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pretty Printing with MarshalIndent<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>pretty, _ := json.MarshalIndent(u, \"\", \"  \")\nfmt.Println(string(pretty))\n\/\/ {\n\/\/   \"name\": \"Asha\",\n\/\/   \"age\": 28,\n\/\/   \"skills\": &#91;\n\/\/     \"Go\",\n\/\/     \"SQL\"\n\/\/   ]\n\/\/ }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In contrast, this version adds line breaks and spaces, which makes logs and config files easy to read. However, it makes the output bigger, so use plain Marshal for Go JSON that travels over the network.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Decoding: Text to Struct<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>input := `{\"name\":\"Ravi\",\"age\":34,\"email\":\"ravi@example.com\",\"skills\":&#91;\"Go\"]}`\n\nvar r User\nif err := json.Unmarshal(&#91;]byte(input), &amp;r); err != nil {\n\tfmt.Println(err)\n\treturn\n}\nfmt.Println(r.Name, r.Age, r.Email, r.Skills)\n\/\/ Ravi 34 ravi@example.com &#91;Go]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>json.Unmarshal<\/code> needs a pointer, written as <code>&amp;r<\/code>, so it can fill the struct. Also, Go simply ignores keys in the input that have no matching field.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Unknown Shapes with map[string]any<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>var anyData map&#91;string]any\njson.Unmarshal(&#91;]byte(`{\"city\":\"Pune\",\"pin\":411001}`), &amp;anyData)\n\nfmt.Println(anyData&#91;\"city\"], anyData&#91;\"pin\"]) \/\/ Pune 411001\nfmt.Printf(\"%T\\n\", anyData&#91;\"pin\"])           \/\/ float64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, when you do not know the shape in advance, decode into a map. However, every number becomes a float64 here, so convert it before you use it as an int.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Streaming Go JSON with Encoder and Decoder<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>dec := json.NewDecoder(strings.NewReader(`{\"name\":\"Meera\",\"age\":25}`))\nvar m User\ndec.Decode(&amp;m)\nfmt.Println(m.Name) \/\/ Meera\n\nenc := json.NewEncoder(os.Stdout)\nenc.Encode(map&#91;string]int{\"count\": 3}) \/\/ {\"count\":3}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, an Encoder writes straight to a file or network connection, and a Decoder reads from one. For example, web servers use them to read request bodies and write responses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go JSON Rules You Must Know<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Go type<\/th><th>Output<\/th><\/tr><\/thead><tbody><tr><td>string<\/td><td>&#8220;text&#8221;<\/td><\/tr><tr><td>int, float64<\/td><td>number<\/td><\/tr><tr><td>bool<\/td><td>true or false<\/td><\/tr><tr><td>slice<\/td><td>array [ ]<\/td><\/tr><tr><td>struct or map<\/td><td>object { }<\/td><\/tr><tr><td>nil pointer or slice<\/td><td>null<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Most importantly, only exported fields, the ones starting with a capital letter, appear in the output. So a struct with only lowercase fields encodes as an empty <code>{}<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go JSON<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td>json: cannot unmarshal string into Go struct field User.age of type int<\/td><td>The input has &#8220;thirty&#8221; for a number.<\/td><td>Send a number or change the field type.<\/td><\/tr><tr><td>invalid character &#8216;}&#8217; looking for beginning of object key string<\/td><td>The JSON has a trailing comma.<\/td><td>Fix the input text.<\/td><\/tr><tr><td>json: Unmarshal(non-pointer main.User)<\/td><td>The code passed r, not &amp;r.<\/td><td>Pass a pointer.<\/td><\/tr><tr><td>Output is {}<\/td><td>All fields are lowercase.<\/td><td>Capitalise the field names.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The lowercase field mistake gives no error at all, so it can waste hours. These questions are common in backend interviews, so practise with my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they are always accurate and up to date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/encoding\/json\">encoding\/json package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/json\">Go blog: JSON and Go<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go JSON uses the encoding\/json package from the standard library.<\/li>\n\n\n\n<li>Marshal turns structs into text, and Unmarshal needs a pointer to fill one.<\/li>\n\n\n\n<li>Tags set key names, omitempty skips empty fields, and &#8220;-&#8221; hides a field.<\/li>\n\n\n\n<li>Only exported fields appear, and map numbers become float64.<\/li>\n\n\n\n<li>Similarly, use Encoder and Decoder for files and network streams.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can now pack and unpack data. Next, we will save it to disk and read it back by working with files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Coming soon: Go File Handling Explained with Examples<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go JSON handling lets your program turn structs into text and read that text back into structs. In this post, you will learn Marshal,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":218,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[42,11,23,21],"swapz_series":[],"class_list":["post-217","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-json","tag-go-lang","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go JSON Encoding and Decoding Explained Simply<\/title>\n<meta name=\"description\" content=\"Learn Go JSON with simple examples: Marshal, Unmarshal, struct tags, omitempty, map[string]any, Encoder, Decoder and common errors.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go JSON Encoding and Decoding Explained Simply\" \/>\n<meta property=\"og:description\" content=\"Learn Go JSON with simple examples: Marshal, Unmarshal, struct tags, omitempty, map[string]any, Encoder, Decoder and common errors.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-15T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go JSON Encoding and Decoding Explained\",\"datePublished\":\"2026-04-15T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/\"},\"wordCount\":697,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-json-encoding-decoding-featured.png\",\"keywords\":[\"Go JSON\",\"Go Lang\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/\",\"name\":\"Go JSON Encoding and Decoding Explained Simply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-json-encoding-decoding-featured.png\",\"datePublished\":\"2026-04-15T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:47+00:00\",\"description\":\"Learn Go JSON with simple examples: Marshal, Unmarshal, struct tags, omitempty, map[string]any, Encoder, Decoder and common errors.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-json-encoding-decoding-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-json-encoding-decoding-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go JSON featured image: cards showing struct tags, Marshal and Unmarshal\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-json-encoding-decoding\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go JSON Encoding and Decoding Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go JSON Encoding and Decoding Explained Simply","description":"Learn Go JSON with simple examples: Marshal, Unmarshal, struct tags, omitempty, map[string]any, Encoder, Decoder and common errors.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/","og_locale":"en_US","og_type":"article","og_title":"Go JSON Encoding and Decoding Explained Simply","og_description":"Learn Go JSON with simple examples: Marshal, Unmarshal, struct tags, omitempty, map[string]any, Encoder, Decoder and common errors.","og_url":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-15T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:47+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go JSON Encoding and Decoding Explained","datePublished":"2026-04-15T03:30:00+00:00","dateModified":"2026-10-10T15:50:47+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/"},"wordCount":697,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-featured.png","keywords":["Go JSON","Go Lang","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/","url":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/","name":"Go JSON Encoding and Decoding Explained Simply","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-featured.png","datePublished":"2026-04-15T03:30:00+00:00","dateModified":"2026-10-10T15:50:47+00:00","description":"Learn Go JSON with simple examples: Marshal, Unmarshal, struct tags, omitempty, map[string]any, Encoder, Decoder and common errors.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-json-encoding-decoding-featured.png","width":2400,"height":1260,"caption":"Go JSON featured image: cards showing struct tags, Marshal and Unmarshal"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go JSON Encoding and Decoding Explained"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":3,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":222,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/217\/revisions\/222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/218"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=217"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}