parser

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package parser provides implementation of a Parser that converts a JSON file to a CSV file. It also provides helper functions to read JSON files and write CSV files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertJSONFile

func ConvertJSONFile(infilePath, outfilePath *string) (*os.File, error)

ConvertJSONFile converts a JSON file at the given path to a CSV file, and returns a pointer to the newly created file, or an error if unsuccessful.

func GetDefaultOutfilePath

func GetDefaultOutfilePath() *string

GetDefaultOutfilePath returns the default file path for an output file.

The default directory for the output file is the root directory of the module. The filename is of the form `data_<seconds_epoch>.output.csv`.

func ReadJSONFile

func ReadJSONFile(path string) (*map[string]interface{}, error)

ReadJSONFile returns a pointer to the map representation of the JSON file at the given path or an error if reading the JSON file was unsuccessful.

func TruncateColumnHeaders

func TruncateColumnHeaders(headers []string) []string

TruncateColumnHeaders returns a slice of strings with the longest common prefix among all the elements removed from each.

func WriteCSVFile

func WriteCSVFile(data [][]string, path *string) (*os.File, error)

WriteCSVFile writes the given 2d slice of strings to a CSV file at the given path. It returns a pointer to the output file, or an error if unsuccessful.

If no path is provided, then a default filename is generated. This function treats the first row in the data argument as the headers for the CSV file.

Types

type Parser

type Parser struct {
	Raw             *map[string]interface{}
	RootObj         oo.Object
	ParsedData      [][]string
	TruncateHeaders bool
	InfilePath      *string
	OutfilePath     *string
	Outfile         *os.File
}

Parser is a representation of a JSON to CSV parsing session.

func NewParser

func NewParser(truncateHeaders bool, infilePath, outfilePath *string) *Parser

NewParser returns a new instance of a Parser.

Jump to

Keyboard shortcuts

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