yukithm / json2csv Goto Github PK
View Code? Open in Web Editor NEWConvert JSON to CSV (go package and command line tool)
License: MIT License
Convert JSON to CSV (go package and command line tool)
License: MIT License
I tried converting JSON('string not struct') to CSV but got an Unsupported JSON structure. error
package main
import (
"github.com/yukithm/json2csv"
)
func main() {
as := `[
{
"id": 1,
"name": "foo",
"favorites": {
"fruits": "apple",
"color": "red"
}
},
{
"id": 2,
"name": "bar",
"favorites": {
"fruits": "orange"
}
},
{
"id": 3,
"name": "baz",
"favorites": {
"fruits": "banana",
"color": "yellow"
}
}
]`
csv, err := json2csv.JSON2CSV(as)
if err != nil {
return
}
println(csv)
}
It seems like the tool can't preserve JSON keys order.
Hi,
I'm trying to install the tool using go get method, but am getting an error:
21-02-03 18:44 % go get github.com/yukithm/json2csv/cmd/json2csv
# github.com/yukithm/json2csv/cmd/json2csv
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:68:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:73:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:77:15: cannot use cli.BoolFlag literal (type cli.BoolFlag) as type cli.Flag in slice literal:
cli.BoolFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:91:13: cannot use func literal (type func(*cli.Context)) as type cli.ActionFunc in assignment
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:105:29: invalid operation: c.Args()[0] (type cli.Args does not support indexing)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:106:36: invalid operation: c.Args()[0] (type cli.Args does not support indexing)
Hey, I had problems with tool converting Arabic texts from JSON to CSV.
I'm looking for a go-based replacement of the npm-based json2csv but there are some features missing that still require some pre-processing of data before it can be fed into this go-based implementation:
There are more functionality that may be added but these are the most important ones that prevent me from switching.
It would be great to add support for them (and maybe others) so a switch of the implementations is easier to do.
I am trying to set a different style, however, I can't seem to know how to do that. I wonder if that is just not available or if I can do that somehow
I new a newCSVWriter that uses SlashStyle
style.
Thanks for the awesome tool
I have noticed that some conversion (can't figure it out the pattern that is causing it) lose its data when converting the content to the csv file.
Steps to reproduce:
b := &bytes.Buffer{}
wr := json2csv.NewCSVWriter(b)
responses := []map[string]interface{}{}
//populate responses
csvContent, err := json2csv.JSON2CSV(responses) // csvContent seems to be complete!
wr.WriteCSV(csvContent)
wr.Flush()
b.Bytes()
At this point when I print the string of the bytes, I get 2 columns missing.
$ go get github.com/yukithm/json2csv/cmd/json2csv
# github.com/yukithm/json2csv/cmd/json2csv
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:68:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:73:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:77:15: cannot use cli.BoolFlag literal (type cli.BoolFlag) as type cli.Flag in slice literal:
cli.BoolFlag does not implement cli.Flag (Apply method has pointer receiver)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:91:13: cannot use func literal (type func(*cli.Context)) as type cli.ActionFunc in assignment
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:105:29: invalid operation: c.Args()[0] (type cli.Args does not support indexing)
go/src/github.com/yukithm/json2csv/cmd/json2csv/main.go:106:36: invalid operation: c.Args()[0] (type cli.Args does not support indexing)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.