Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
Output CSV based on an array of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpurra committed Jul 11, 2014
1 parent d6fc5c5 commit a5be815
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/util/array-of-objects-to-csv.sh
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e

read -d '' getCSV <<-'EOF' || true
def toHeader:
to_entries
| map(
.key
| @text
)
| @csv;
def toLine:
to_entries
| map(
.value
| @text
)
| @csv;
def toLines:
map(toLine)
| join("\\n");
(.[0] | toHeader),
toLines
EOF

cat | jq --raw-output "$getCSV"

0 comments on commit a5be815

Please sign in to comment.