I am constructing a reply on a restAPI and using json.NewEncoder.Encode() to generate the JSON reply ( note : w is responsewriter).
u := Reply{Id: id, Status: "progress", Message: ""}
json.NewEncoder(w).Encode(u)
This works fine.
But I then have the other situation where Message will be populated with a string that is already in JSON format:
RetMessage := "{"debug": "on", "window": { "width": 500, "height": 500}}"
u := Reply{Id: id, Status: "progress", Message: RetMessage}
json.NewEncoder(w).Encode(u)
Then the reply will be the JSON with escaped quotations etc, which makes sense of course as it parses it as strings to JSON, but it of course breaks the concept as I would like the RetMessage to be passed on as it is, where the others I would like to be encoded to JSON.
Is there any way I can get around this in a smart way? The content in RetMessage is coming from a file so I can't change that the RetMessage sometimes do come as JSON encoded already.