title: How to parse nested arrays / sub tables in TOML?
body: <p>I'm starting with <strong>Go</strong> and the official <a href="https://golang.org/doc/" rel="nofollow noreferrer">documentation</a> seems more for people who know Go already and just want to look stuff up. I'm hoping for a little nudge in the right direction here.</p>
  
  <p><strong>What I'm looking to do:</strong> Parse a <code>TOML</code> config file with <em>BurntSushi's</em> TOML parser that consists of several elements sharing the same base characteristics. </p>
  
  <p><strong>Where I'm stuck:</strong> I want each item's respective parts to be listed with the item. So far I can only get one of them by its index. What I'm looking for is how to set it up in a way that lists all sub parts of the respective index instead of just a specific one. I can get a JSON list with <code>[:]</code> but can't seem to adapt that to get <em>normal</em> output.</p>
  
  <p>Initially I had considered <code>[[item.part.001]]</code> and so on because it looked right in the online JSON parsers, but wasn't able to figure out how to read that properly into Go. Since I'm stuck anyway, I'm open to both types, whatever works best.</p>
  
  <p>Thanks in advance. Here are the files as an abbreviated minimum working example.</p>
  
  <hr>
  
  <blockquote>
    <p>demo.toml</p>
  </blockquote>
  
  <pre><code># — — — — —  — — — — — — — — — — — — — — — — — — 
  #                   First Item
  # — — — — —  — — — — — — — — — — — — — — — — — — 
  
  [[item]]
  itemname = "Fragments"
  itemdesc = "This one can get a bit longer."
  
      [item.attributes]
      material = "Basematname"
      light    = "Lightname"
      transpc  = "full"
      displace = "height"
  
      [[item.part]]
      partname = "Shard"
      partlink = "active"
  
      [[item.part]]
      partname = "Tear"
      partlink = "deferred"
  
      [[item.part]]
      partname = "crater"
      partlink = "disabled"
  
  
  # — — — — —  — — — — — — — — — — — — — — — — — — 
  #                   Second Item
  # — — — — —  — — — — — — — — — — — — — — — — — — 
  
  [[item]]
  itemname = "Splash"
  itemdesc = "This one also can get a bit longer."
  
      [item.attributes]
      material = "Other Basematname"
      light    = "Other Lightname"
      transpc  = "half"
      displace = "bump"
  
      [[item.part]]
      partname = "Drops"
      partlink = "active"
  
      [[item.part]]
      partname = "Wave"
      partlink = "deferred"
  </code></pre>
  
  <hr>
  
  <blockquote>
    <p>demo.go</p>
  </blockquote>
  
  <pre><code>package main 
  
  import (
      "fmt"
      "github.com/BurntSushi/toml"
  )
  
  type item struct {
      ItemName    string
      ItemDesc    string
      Attributes  attributes
      Part        []part
  }
  
  type part struct {
      PartName    string
      PartLink    string
  }
  
  type attributes struct {
      Material    string
      Light       string
      TransPC     string
      Displace    string
  }
  
  type items struct {
      Item    []item
  }
  
  
  
  func main() {
  
  
      var allitems items
  
      if _, err := toml.DecodeFile("demo.toml", &amp;allitems); err != nil {
          fmt.Println(err)
          return
      }
  
      fmt.Printf("\n")
  
      for _, items := range allitems.Item {
          fmt.Printf("    Item Name: %s \n", items.ItemName)
          fmt.Printf("  Description: %s \n\n", items.ItemDesc)
  
          fmt.Printf("     Material: %s \n", items.Attributes.Material)
          fmt.Printf("     Lightmap: %s \n", items.Attributes.Light)
          fmt.Printf(" TL Precision: %s \n", items.Attributes.TransPC)
          fmt.Printf("   DP Channel: %s \n", items.Attributes.Displace)
  
  
          fmt.Printf("    Part Name: %s \n", items.Part[0].PartName)
          fmt.Printf("    Part Link: %s \n", items.Part[0].PartLink)
          #                                             ^
          #                              That's where [:] won't do it.   
  
          fmt.Printf("\n────────────────────────────────────────────────────┤\n\n")
  
  
      }
  
      fmt.Printf("\n")
  
  
  }
  </code></pre>