30 lines
826 B
Bash
Executable file
30 lines
826 B
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
|
|
|
|
input="$SCRIPT_DIR/data/restaurants.csv"
|
|
output="$SCRIPT_DIR/data/restaurants.jsonl"
|
|
|
|
|
|
# In order:
|
|
# - Convert CSV to JSON
|
|
# - Convert JSON array in JSON lines notation
|
|
# - Remove last line (which is all `null`)
|
|
cat "$input" | jq -s --raw-input --raw-output \
|
|
'split("\n") | .[1:-1] | map(split(",")) |
|
|
map({
|
|
"id": .[0],
|
|
"name": .[1],
|
|
"city": .[2],
|
|
"location": {
|
|
"lon": .[8] | sub("^\"\\["; "") | sub("\\s*"; "") | tonumber,
|
|
"lat": .[9] | sub("\\]\"$"; "") | sub("\\s*"; "") | tonumber,
|
|
},
|
|
"averageCostForTwo": .[3],
|
|
"aggregateRating": .[4],
|
|
"ratingText": .[5],
|
|
"votes": .[6],
|
|
"date": .[7]
|
|
})' "$input" | \
|
|
jq -c '.[]' > "$output"
|