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
In general, if your jq has the inputs
built-in filter (available since jq 1.5), then it is better to use it rather than the -s command-line option.
Here in any case is a solution using inputs
. This solution is also variable-free.
{"occurrences":
[inputs
| select(length > 0)
| . / ";"
| {"position": [.[0], .[1]],
"taxo": {"espece": .[2]}} ]}
The above of course assumes that the file has semicolon-separated fields in each line, and that there are none of the complications associated with CSV files.
If the input has fields that are strictly delimited by a single character, then jq should have no problems handling it. Otherwise, it might be best to use a tool that can reliably convert to the TSV (tab-separated value) format, which jq can handle directly.