Converting CSV to JSON in bash

前端 未结 9 1876
梦毁少年i
梦毁少年i 2021-02-04 03:12

Trying to convert a CSV file into a JSON

Here is two sample lines :

-21.3214077;55.4851413;Ruizia cordata
-21.3213078;55.4849803;Cossinia pinnata
         


        
9条回答
  •  粉色の甜心
    2021-02-04 03:40

    Because the jq solution does not handle CSV escaping, column names at the first line, commented-out lines and other common CSV "features", I have extended the CSV Cruncher tool to allow reading CSV and writing it as JSON. It's not exactly "Bash", but neither is jq :)

    It's primarily a CSV-as-SQL processing app, so it's not completely trivial, but here is the trick:

    ./crunch -in myfile.csv -out output.csv --json -sql 'SELECT * FROM myfile'
    

    It also allows output as JSON object per line or proper JSON array. See the documentation.

    It's in beta quality, so all feedback or pull requests are welcome.

提交回复
热议问题