jehiah / json2csv

command line tool to convert json to csv
MIT License
801 stars 94 forks source link

Replace encoding/json with github.com/buger/jsonparser #41

Open fprimex opened 2 years ago

fprimex commented 2 years ago

Hi. I doubt you actually want to merge this PR, so this is more of an FYI. My goal in working with ios_system and a-shell has been to get this working as a wasm binary. To achieve that I wanted to compile it with tinygo, which seems to be the easiest and most functional way to get wasm binaries with Go.

Unfortunately, encoding/json does not work with tinygo because tinygo does not have a complete implementation of reflect. It looks like that is a work in progress, but it's still a big challenge to tackle.

I found jsonparser, which appeared to both offer everything that's needed and also does not require the reflect package. It also does not need to unmarshal to a struct like other packages, which I found do not usually support map[string]interface{} as a target.

Anyway, after making these changes I can compile with:

tinygo build -no-debug -o json2csv.wasm -target wasi .

then download the wasm to a-shell's Documents/bin folder, and it works there on the iPhone / iPad just like the amd64 binary does on my iMac.

Both the amd64 and wasm versions pass go test :)

fprimex commented 2 years ago
fprimex commented 2 years ago

Also, I'm not sure if this is standard with go test, but I found that running go test on this project masked stderr, which would have helped me tremendously in resolving one of the test cases.