Skip to content

Instantly share code, notes, and snippets.

@ober

ober/convert-csv-to-json.ss Secret

Created Nov 18, 2020
Embed
What would you like to do?
Proper way to do the destructuring bind?
#!/usr/bin/env gxi
(import
:gerbil/gambit
:gerbil/gambit/ports
:std/format
:std/generic
:std/iter
:std/misc/list
:std/misc/ports
:std/sugar
:std/text/csv
:std/text/json)
(def test-csv "A,B,C,D,E,F,G
1,2,3,4,5,6,7
foo,bar,baz,krunk,kaffe,deadbeef,feedface")
(def (main . args)
(let* ((data (call-with-input-string test-csv read-csv-lines))
(header (car data))
(results []))
(for (line (cdr data))
(with ([
A
B
C
D
E
F
G
] line)
(set! results (cons (hash
("A" A)
("B" B)
("C" C)
("D" D)
("E" E)
("F" F)
("G" G))
results))))
(displayln (json-object->string results))))
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.