title: Golang parse complex json
body: <p>I am new to golang and json and currently struggle to parse the json out from a system. </p>
  
  <p>I've read a couple of blog posts on dynamic json in go and also tried the tools like <a href="https://mholt.github.io/json-to-go/" rel="nofollow">json2GoStructs</a>
  Parsing my json file with this tools just gave me a huge structs which I found a bit messy. Also I had no idea how to get the info im interested in.</p>
  
  <p>So, here are my <strong>problems</strong>:</p>
  
  <ol>
  <li>How do I get to the info I am interested in?</li>
  <li>What is the best approach to parse complex json?</li>
  </ol>
  
  <p>I am only <strong>interested</strong> into the following 3 json fields:</p>
  
  <pre><code>Name
  Guid
  Task -&gt; Property -&gt; Name: Error
  </code></pre>
  
  <p>I'm thankful for every tip, code snippet or explanation!</p>
  
  <p><strong>This is what I got so far (mostly from a tutorial):</strong></p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
      "io/ioutil"
  )
  
  func checkErr(err error) {
      if err != nil {
          panic(err)
      }
  }
  
  func readFile(filePath string) []byte {
      data, err := ioutil.ReadFile(filePath)
      checkErr(err)
      return data
  }
  
  func main() {
      path := "/Users/andi/Documents/tmp/wfsJob.json"
      data := readFile(path)
  
      var f interface{}
  
      err := json.Unmarshal(data, &amp;f)
      checkErr(err)
  
      m := f.(map[string]interface{})
  
      for k, v := range m {
          switch vv := v.(type) {
          case string:
              fmt.Println(k, "is string", vv)
          case int:
              fmt.Println(k, "is int", vv)
          case []interface{}:
              fmt.Println(k, "is an array:")
              for i, u := range vv {
                  fmt.Println(i, u)
              }
          default:
              fmt.Println(k, "is of a type I don't know how to handle")
          }
      }
  }
  </code></pre>