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 ¶
- func ConvertJSONFile(infilePath, outfilePath *string) (*os.File, error)
- func GetDefaultOutfilePath() *string
- func ReadJSONFile(path string) (*map[string]interface{}, error)
- func TruncateColumnHeaders(headers []string) []string
- func WriteCSVFile(data [][]string, path *string) (*os.File, error)
- type Parser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertJSONFile ¶
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 ¶
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 ¶
TruncateColumnHeaders returns a slice of strings with the longest common prefix among all the elements removed from each.
func WriteCSVFile ¶
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.