I am trying to create json serialized input data but not sure how to add the backslash () characters. Code below which can convert struct to json but not the way I require
Output: {"new":{"Id":"1","Class":"23"}} Expected: {\"new\":{\"Id\":\"1\",\"Class\":\"23\"}}
package main
import (
"encoding/json"
"fmt"
)
type Txn struct {
Id string `json:"Id"`
Class string `json:"Class"`
}
type Send struct {
New Txn `json:"new"`
}
func main() {
fmt.Println("Creating serialized json")
t := Txn{}
t.Id = "1"
t.Class = "23"
fmt.Println(t)
p := Send{}
p.New = t
fmt.Println("my p is", p)
b, err := json.Marshal(p)
if err != nil {
fmt.Println("found some error ", err)
}
fmt.Println(string(b))
}