mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
Packaged 14 scripts from .bin/ into packages/ with proper dependency declarations (writers.writeDashBin/writeBashBin/writePython3Bin): - 256color → two56color (terminal color chart) - avesta.sed → avesta (Avestan transliteration) - bvg.sh → bvg (Berlin transit disruptions) - unicode → charinfo (Unicode character info) - chunk-pdf → chunk-pdf (split PDFs by page count) - csv2json → csv2json (CSV to JSON converter) - fix-sd.sh → fix-sd (exFAT SD card recovery, improved output handling) - json2csv → json2csv (JSON to CSV converter) - mp3player-write → mp3player-write (audio conversion for MP3 players) - mushakkil.sh → mushakkil (Arabic diacritization) - nix-haddock-index → nix-haddock-index (GHC Haddock index generator) - pdf-ocr.sh → pdf-ocr (OCR PDFs via tesseract) - prospekte.sh → prospekte (German supermarket flyer browser) - readme → readme (GitHub README as man page) All added to overlay and packages output. .bin/ directory removed.
33 lines
879 B
Nix
33 lines
879 B
Nix
# Convert JSON array of objects to CSV
|
|
{
|
|
writers,
|
|
python3,
|
|
}:
|
|
writers.writePython3Bin "json2csv" {
|
|
flakeIgnore = [ "E501" ];
|
|
} ''
|
|
import csv
|
|
import json
|
|
import sys
|
|
|
|
if __name__ == "__main__":
|
|
json_list = json.load(sys.stdin)
|
|
if not isinstance(json_list, list):
|
|
print("JSON object is not a list.", file=sys.stderr)
|
|
sys.exit(1)
|
|
if len(json_list) == 0:
|
|
print("JSON list is empty.", file=sys.stderr)
|
|
sys.exit(1)
|
|
keys = set()
|
|
for element in json_list:
|
|
if isinstance(element, dict):
|
|
keys |= element.keys()
|
|
else:
|
|
print("Non-dict element:", element, file=sys.stderr)
|
|
sys.exit(1)
|
|
writer = csv.DictWriter(sys.stdout, fieldnames=list(keys))
|
|
writer.writeheader()
|
|
for element in json_list:
|
|
writer.writerow(element)
|
|
''
|