title: Extra bracket in json marshaling
body: <p>I want to combine a series of small json files into a single one (vscode snippet). Small files content looks like:</p>
  <pre><code>&quot;baz&quot;: {
      &quot;foo&quot;: &quot;a&quot;,
      &quot;bar&quot;: &quot;b&quot;
  }
  </code></pre>
  <p>and final file <strong>should</strong> looks like:</p>
  <pre><code>{
       &quot;baz&quot;: {
           &quot;foo&quot;: &quot;a&quot;,
           &quot;bar&quot;: &quot;b&quot;
       },
       &quot;baz2&quot;: {
           &quot;foo&quot;: [&quot;a&quot;, &quot;b&quot;],
           &quot;bar&quot;: &quot;c&quot;
       },
       ...
  }
  </code></pre>
  <p>but I get extra brackets over each <code>baz</code>:</p>
  <pre><code>{
       &quot;baz&quot;: [{
           &quot;foo&quot;: &quot;a&quot;,
           &quot;bar&quot;: &quot;b&quot;
       }],
       &quot;baz2&quot;: [{
           &quot;foo&quot;: [&quot;a&quot;, &quot;b&quot;],
           &quot;bar&quot;: &quot;c&quot;
       }],
       ...
  }
  </code></pre>
  <p>Here is the code:</p>
  <pre><code>package main
  
  import (
      &quot;encoding/json&quot;
      &quot;io/ioutil&quot;
      &quot;log&quot;
      &quot;os&quot;
      &quot;path/filepath&quot;
      &quot;strings&quot;
  )
  
  const root = &quot;rootFolder&quot;
  const tabSpace = &quot;  &quot;
  
  type Snippet struct {
      Prefix      interface{} `json:&quot;prefix&quot;`
      Body        string      `json:&quot;body&quot;`
      Description string      `json:&quot;description&quot;`
  }
  
  func main() {
      cwd, _ := os.Getwd()
      snippetFile := filepath.Join(cwd, &quot;snippets&quot;, &quot;sampleSnippet.json&quot;)
      snippetFile = filepath.FromSlash(snippetFile)
  
      os.Chdir(root)
      folders := getFolders(&quot;.&quot;)
      snippets := map[string][]Snippet{}
  
      for _, folder := range folders {
          files := getFiles(folder)
          for _, file := range files {
              os.Chdir(folder)
              snippetName := folder + &quot;.&quot; + strings.TrimSuffix(file, &quot;.json&quot;)
              jsonFileBytes, _ := ioutil.ReadFile(file)
              var snippet Snippet
              json.Unmarshal(jsonFileBytes, &amp;snippet)
              namedSnippet := map[string]Snippet{
                  snippetName: snippet,
              }
              for k, v := range namedSnippet {
                  snippets[k] = append(snippets[k], v)
              }
              os.Chdir(&quot;..&quot;)
          }
      }
      output, _ := json.MarshalIndent(snippets, &quot;&quot;, &quot;  &quot;)
      _ = ioutil.WriteFile(snippetFile, output, 0755)
  }
  
  func getFolders(root string) []string {
      var folders []string
      files, err := ioutil.ReadDir(root)
      if err != nil {
          panic(err)
      }
      for _, fileInfo := range files {
          if fileInfo.IsDir() {
              folders = append(folders, fileInfo.Name())
          }
      }
      return folders
  }
  
  func getFiles(dir string) []string {
      files, err := ioutil.ReadDir(dir)
      if err != nil {
          log.Fatal(err)
      }
  
      var result []string
      for _, file := range files {
          result = append(result, file.Name())
      }
      return result
  }
  </code></pre>