How to Print an user defined message into struct to parse it as json encoding

Hello All,

I have a struct

type Response struct {
Status string json:"status"
Message string json:"message"

i have strings

stat := “Valid”
msg := fmt.Sprinf(abc"+" cde)

i want this stat and msg to be passed to the struct Response and use it in json encoding how can i achieve it

Just create a var of type Reponse and assign each property its corresponding value.

    stat := “Valid”
    msg := fmt.Sprinf(abc"+" cde)
    newResponse := Response{ Status:stat, Message:msg}
    b, err := json.Marshal(newResponse)

This worked thanks a lot

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.