Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clojure csv with escaped comma

I am trying to parse a csv string in clojure with escaped commas and no quote around fields like this one

"test1\,test2,test3"

I tried this libraries:

  • [org.clojure/data.csv "0.1.2"]
  • [cljcsv "1.3.1"]
  • [clojure-csv/clojure-csv "2.0.0-alpha1"]

But none of them seems capable to recognize this correctly as ["test1,test2" "test3"] Does someone know a library which can do this?

Thanks in advance

like image 625
Finn Avatar asked Dec 02 '25 10:12

Finn


1 Answers

You're not exactly parsing CSV data, but some derivation of the convention (note I didn't write "standard").

In CSV, commas are not escaped. That is something leaking into your data from C/C++/Java string escaping. If it were typical CSV, it would be written like this

"a,b",c

Which clojure-csv supports.

user=> (csv/parse-csv (str "\"a,b\",c")) 
(["a,b" "c"])

You likely will have to write your own parser, or extend one of the aforementioned libraries, to handle this case.

like image 53
noahlz Avatar answered Dec 05 '25 15:12

noahlz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!