json2csv
json2csv copied to clipboard
Replace encoding/json with github.com/buger/jsonparser
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
:)
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.