<commit_before>package main

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"log"
	"os"
	"path"
	"text/template"
)

type JSONData map[string]interface{}

func tmplFilename(t *template.Template, jsd JSONData) (string, error) {
	var fnBuf bytes.Buffer
	err := t.Execute(&fnBuf, jsd)
	if err != nil {
		return "", err
	}
	return fnBuf.String(), nil
}

func main() {
	if len(os.Args) != 2 {
		log.Fatal("Usage: json2files [output filename template]\n")
	}

	fileTmpl := os.Args[1]

	tmpl, err := template.New("filename").Parse(fileTmpl)
	if err != nil {
		log.Fatal(err)
	}

	dec := json.NewDecoder(os.Stdin)

	for {
		var jsd JSONData
		if err := dec.Decode(&jsd); err != nil {
			log.Fatal(err)
		}

		fn, err := tmplFilename(tmpl, jsd)
		if err != nil {
			log.Fatal(err)
		}

		basepath := path.Dir(fn)
		if err := os.MkdirAll(basepath, 0770); err != nil {
			log.Fatal(err)
		}

		outJSON, err := json.MarshalIndent(jsd, "", " ")
		if err != nil {
			log.Fatal(err)
		}

		if err := ioutil.WriteFile(fn, outJSON, 0640); err != nil {
			log.Fatal(err)
		}
	}
}
<commit_msg>Indent the output JSON by two spaces.<commit_after>package main

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"log"
	"os"
	"path"
	"text/template"
)

type JSONData map[string]interface{}

func tmplFilename(t *template.Template, jsd JSONData) (string, error) {
	var fnBuf bytes.Buffer
	err := t.Execute(&fnBuf, jsd)
	if err != nil {
		return "", err
	}
	return fnBuf.String(), nil
}

func main() {
	if len(os.Args) != 2 {
		log.Fatal("Usage: json2files [output filename template]\n")
	}

	fileTmpl := os.Args[1]

	tmpl, err := template.New("filename").Parse(fileTmpl)
	if err != nil {
		log.Fatal(err)
	}

	dec := json.NewDecoder(os.Stdin)

	for {
		var jsd JSONData
		if err := dec.Decode(&jsd); err != nil {
			log.Fatal(err)
		}

		fn, err := tmplFilename(tmpl, jsd)
		if err != nil {
			log.Fatal(err)
		}

		basepath := path.Dir(fn)
		if err := os.MkdirAll(basepath, 0770); err != nil {
			log.Fatal(err)
		}

		outJSON, err := json.MarshalIndent(jsd, "", "  ")
		if err != nil {
			log.Fatal(err)
		}

		if err := ioutil.WriteFile(fn, outJSON, 0640); err != nil {
			log.Fatal(err)
		}
	}
}

{'fraction_non_alphanumeric': 0.1714942528735632, 'fraction_numerical': 0.010114942528735632, 'mean_word_length': 3.2583170254403133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6559856', 'n_tokens_mistral': 987, 'n_tokens_neox': 884, 'n_words': 200}