json2csv

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2018 License: MIT Imports: 6 Imported by: 0

README

JSON to CSV conversion

GoDoc Goreport Build Status codecov

Converts arbitrary JSON data to CSV. Does it make sense? Not always, but it can be useful for the right use-case :)

Usage:

func main() {
	json2csv.Convert(strings.NewReader(`[
{
  "foo": "bar",
  "baz": [{"a":"b"}, 1, 1.3]
},
{
  "foo": "fi fum",
  "baz": [{"a":"c"}, 3],
  "extra": "fine"
},
"it's JSON, what do you expect?"
]`), os.Stdout)
	// Output:
	// baz.0.a,baz.1,baz.2,extra,foo,text
	// b,1,1.3,,bar,
	// c,3,,fine,fi fum,
	// ,,,,,"it's JSON, what do you expect?"
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(r io.Reader, w io.Writer) error

Convert JSON to CSV

Example
package main

import (
	"os"
	"strings"

	"github.com/Sydsvenskan/json2csv"
)

func main() {
	json2csv.Convert(strings.NewReader(`[
{
  "foo": "bar",
  "baz": [{"a":"b"}, 1, 1.3]
},
{
  "foo": "fi fum",
  "baz": [{"a":"c"}, 3],
  "extra": "fine"
},
"it's JSON, what do you expect?"
]`), os.Stdout)
}
Output:

baz.0.a,baz.1,baz.2,extra,foo,text
b,1,1.3,,bar,
c,3,,fine,fi fum,
,,,,,"it's JSON, what do you expect?"

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL