title: Write Struct to Json File using Struct Fields (not json keys)
body: <p>How can I read a json file into a struct, and then Marshal it back out to a json string with the Struct fields as keys (rather than the original json keys)?</p>
  
  <p>(see <code>Desired Output to Json File</code> below...)</p>
  
  <p>Code:</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
      "io/ioutil"
  )
  
  type Rankings struct {
      Keyword  string `json:"keyword"`
      GetCount uint32 `json:"get_count"`
      Engine   string `json:"engine"`
      Locale   string `json:"locale"`
      Mobile   bool   `json:"mobile"`
  }
  
  func main() {
      var jsonBlob = []byte(`
          {"keyword":"hipaa compliance form", "get_count":157, "engine":"google", "locale":"en-us", "mobile":false}
      `)
      rankings := Rankings{}
      err := json.Unmarshal(jsonBlob, &amp;rankings)
      if err != nil {
          // nozzle.printError("opening config file", err.Error())
      }
  
      rankingsJson, _ := json.Marshal(rankings)
      err = ioutil.WriteFile("output.json", rankingsJson, 0644)
      fmt.Printf("%+v", rankings)
  }
  </code></pre>
  
  <p>Output on screen:</p>
  
  <pre><code>{Keyword:hipaa compliance form GetCount:157 Engine:google Locale:en-us Mobile:false}
  </code></pre>
  
  <p>Output to Json File: </p>
  
  <pre><code>{"keyword":"hipaa compliance form","get_count":157,"engine":"google","locale":"en-us","mobile":false}
  </code></pre>
  
  <p><strong><em>Desired Output to Json File:</em></strong></p>
  
  <pre><code>{"Keyword":"hipaa compliance form","GetCount":157,"Engine":"google","Locale":"en-us","Mobile":false}
  </code></pre>