Skip to content

DeanPDX/goff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang File Formatter (GOFF) Go Reference Go Report Card

This is a very quick util I started building to help convert CSV to JSON. Right now it only supports CSV > JSON with minimal error recovery.

Demo

Demonstration

Usage

Assuming the following CSV file named data.csv:

ID,Name,Salary
1,James Murphy,32000.99
2,Jane Doe,44000
3,John Doe,12345

... the output of goff data.csv would result in a data.json file with the following contents:

[
	{
		"ID": "1",
		"Name": "James Murphy",
		"Salary": "32000.99"
	},
	{
		"ID": "2",
		"Name": "Jane Doe",
		"Salary": "44000"
	},
	{
		"ID": "3",
		"Name": "John Doe",
		"Salary": "12345"
	}
]

Usage is goff <input file path> <output file path>. Example commands:

# Read data.csv and output myjsondata.json:
goff data.csv myjsondata.json
# Read data.csv and default second param to <inputFileName>.json. In this case data.json:
goff data.csv

Installation

Make sure you have golang installed and your gopath set, then run go get:

go get github.com/DeanPDX/goff/cmd/goff

If everything goes as planned, you should be able to run goff and see the usage notes:

v0.1
usage:

goff <input file path> <output file path>

the second argument (output file path) is optional
and will default to the name of your input file with
the appropriate extension.

Limitations

  • We only support CSV > JSON. Consider adding other file types.
  • Data types are always strings. Consider being more clever about data types for formats that support more complex types (like JSON).
  • Malformed file error handling could be better. See this question in StackOverflow. We have a similar problem in the event that incorrect newlines are used. Consider using transform.Transformer to clean up malformed files.

Future Updates

  • Convert read/write to buffered IO. This will allow easier unit testing.
  • Get some test coverage.