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 👍.