title: Marshall JSON Slice to valid JSON
body: <p>I'm building a REST API using Golang but I'm having some troubles trying to correctly Marshalling a Json Slice. I've been scratching my head for a while now, even after looking to several questions and answer and on the web.</p>
  
  <p>Essentially, I have a <strong>Redis</strong> client that called after a call <code>-X GET /todo/</code> spits up a slice of <code>todos</code></p>
  
  <pre><code>[{"content":"test6","id":"46"} {"content":"test5","id":"45"}] //[]string
  </code></pre>
  
  <p>Now, I want to return a given <code>Response</code> based on the fact that I found <code>todos</code> or not, so I have a <code>Struct</code> like</p>
  
  <pre><code>type Response struct {
      Status string
      Data []string
  }
  </code></pre>
  
  <p>Then, If I found some <code>todos</code> I just <code>Marshal</code> a json with</p>
  
  <pre><code>if(len(todos) &gt; 0){
      res := SliceResponse{"Ok", todos}
      response, _ = json.Marshal(res)
  }
  </code></pre>
  
  <p>And, In order to remove unnecessary <code>\</code> inside the response, I use <code>bytes.Replace</code> like</p>
  
  <pre><code>response = bytes.Replace(response, []byte("\\"), []byte(""), -1)
  </code></pre>
  
  <p>Finally, getting</p>
  
  <pre><code>{
     "Status" : "Ok",
     "Data" : [
                "{"content":"test6","id":"46"}",
                "{"content":"test5","id":"45"}"
      ]
  }
  </code></pre>
  
  <p>As you can see each <code>"</code> before each <code>{</code> and after each <code>}</code>, excluding the first and the last ones, are clearly wrong.
  While the correct JSON would be</p>
  
  <pre><code>{
      "Status": "Ok",
      "Data": [{
          "content ": "test6",
          "id ": "46"
      }, {
          "content ": "test5",
          "id ": "45"
      }]
  }
  </code></pre>
  
  <blockquote>
    <p>I successfully managed to get them off by finding their index and trim them off and
    also with regex but I was wondering.</p>
  </blockquote>
  
  <p><strong>Is there a clean and better way to achieve that?</strong></p>