how to convert json string to map in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To convert json string to map in golang, just use json.Marshal([]byte[jsonString], &x) method and pass your json string, it will convert json string into map.

Follow the below tutorial if you are struggling with installing GO in windows.

Today, I will show you how do I convert json string to map in golang, as above mentioned I’m going to use json.Marshal([]byte[jsonString], &x) way.

The strings package provide json.Marshal([]byte[jsonString], &x) method.

Let’s start our Golang convert json string to map example

Convert whole json string into map example


package main
import (
func main() {
    jsonStr := `{"domain-1":"", "domain-2":"", "domain-3": ""}`
    x := map[string]string{}
    json.Unmarshal([]byte(jsonStr), &x)

In the above example, we have converted json string to map and printed in golang console. let’s check the output.



Try it Yourself

I hope it helps you, All the best 👍.

Premium Content

You can get all the below premium content directly in your mail when you subscribe us


Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Related Posts