title: JSON decoding error in Go: "invalid character '\\' looking for beginning of object key string"
body: <p>I'm using the <code>vpp</code> package of <a href="https://micromdm.io/" rel="nofollow noreferrer">MicroMDM</a> but noticed that initializing a VPP client, which was working before, has stopped working. The error I get occurs in the client's <code>GetClientContext()</code> method (<a href="https://github.com/micromdm/micromdm/blob/ea5c0a3865e87f5de04a58dc2c67b5fa6f6fd7de/vpp/clientconfigsrv.go#L99-L117" rel="nofollow noreferrer">https://github.com/micromdm/micromdm/blob/ea5c0a3865e87f5de04a58dc2c67b5fa6f6fd7de/vpp/clientconfigsrv.go#L99-L117</a>), which I've modified with a <code>fmt.Println()</code> call to print the <code>context</code>:</p>
  
  <pre><code>// GetClientContext gets the values that determine which mdm server is associated with a VPP account token
  func (c *Client) GetClientContext() (*ClientContext, error) {
      // Get the ClientConfigSrv info
      clientConfigSrv, err := c.GetClientConfigSrv()
      if err != nil {
          return nil, errors.Wrap(err, "get ClientContext request")
      }
  
      // Get the ClientContext string
      var context = clientConfigSrv.ClientContext
      fmt.Println(context)
  
      // Convert the string to a ClientContext type
      var clientContext ClientContext
      err = json.NewDecoder(strings.NewReader(context)).Decode(&amp;clientContext)
      if err != nil {
          return nil, errors.Wrap(err, "decode ClientContext")
      }
  
      return &amp;clientContext, nil
  }
  </code></pre>
  
  <p>where <code>ClientContext</code> is the following struct (<a href="https://github.com/micromdm/micromdm/blob/ea5c0a3865e87f5de04a58dc2c67b5fa6f6fd7de/vpp/clientconfigsrv.go#L10-L14" rel="nofollow noreferrer">https://github.com/micromdm/micromdm/blob/ea5c0a3865e87f5de04a58dc2c67b5fa6f6fd7de/vpp/clientconfigsrv.go#L10-L14</a>):</p>
  
  <pre><code>// Contains information that associates your particular mdm server to a VPP account token
  type ClientContext struct {
      HostName string `json:"hostname"`
      GUID     string `json:"guid"`
  }
  </code></pre>
  
  <p>when I run a script that invokes <code>vpp.NewClient()</code> (which, in turn, invokes this method), I see the following output:</p>
  
  <pre><code>&gt; go run main.go getVPPAssets
  INFO[0000] Using config file: .vpp-client.env           
  {\"hostname\":\"https://your.server.com\",\"guid\":\"7c66e635-ef07-4e26-86a3-c953e4e8f16d\"}
  FATA[0000] Failed to initialize VPP client: GetClientContext request: decode ClientContext: invalid character '\\' looking for beginning of object key string 
  exit status 1
  </code></pre>
  
  <p>Note that the line with </p>
  
  <pre><code>{\"hostname\":\"https://your.server.com\",\"guid\":\"7c66e635-ef07-4e26-86a3-c953e4e8f16d\"}
  </code></pre>
  
  <p>is produced by the <code>fmt.Println()</code> statement I added. I've tried to reproduce this error with the following minimal example:</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
      "strings"
  
      "github.com/sirupsen/logrus"
  )
  
  type ClientContext struct {
      HostName string `json:"hostname"`
      GUID     string `json:"guid"`
  }
  
  func main() {
      context := "{\"hostname\":\"https://your.server.com\",\"guid\":\"7c66e635-ef07-4e26-86a3-c953e4e8f16d\"}"
  
      var clientContext ClientContext
      if err := json.NewDecoder(strings.NewReader(context)).Decode(&amp;clientContext); err != nil {
          logrus.Fatalf("decode ClientContext: %v", err)
      }
  
      fmt.Printf("%+v\n", clientContext)
  }
  </code></pre>
  
  <p>However, this example decodes the <code>clientConfigSrv.ClientContext</code> string into a <code>ClientContext</code> correctly.</p>
  
  <p>I believe there is something about the escaping of quotes that has changed in the response returned by Apple's VPP service and is causing this decoder to choke; any ideas how to fix this error?</p>