func (w *CSVWriter) writeCSV(results []KeyValue) error {
	pts, err := allPointers(results)
	if err != nil {
		return err
	}
	sort.Sort(pts)
	keys := pts.Strings()
	header := w.getHeader(pts)
	if err := w.Write(header); err != nil {
		return err
	}
	for _, result := range results {
		record := toRecord(result, keys)
		if err := w.Write(record); err != nil {
			return err
		}
	}
	w.Flush()
	if err := w.Error(); err != nil {
		return err
	}
	return nil
}
WriteCSV writes CSV data.
package json2csv
import (
	"encoding/csv"
	"io"
	"sort"
	"github.com/yukithm/json2csv/jsonpointer"
)
type KeyStyle uint
const (
	JSONPointerStyle KeyStyle = iota
	SlashStyle
	DotNotationStyle
	DotBracketStyle
)
type CSVWriter struct {
	*csv.Writer
	HeaderStyle KeyStyle
	Transpose   bool
}
func NewCSVWriter(w io.Writer) *CSVWriter {
	return &CSVWriter{
		csv.NewWriter(w),
		JSONPointerStyle,
		false,
	}
}
func (w *CSVWriter) WriteCSV(results []KeyValue) error {
	if w.Transpose {
		return w.writeTransposedCSV(results)
	}
	return w.writeCSV(results)
}