packages feed

csv-nptools 0.3.0 → 0.4.0

raw patch · 2 files changed

+13/−9 lines, 2 filesdep +aesondep +bytestringdep +textdep −json

Dependencies added: aeson, bytestring, text, vector

Dependencies removed: json

Files

csv-nptools.cabal view
@@ -1,6 +1,6 @@ Name:           csv-nptools Cabal-Version:  >=1.4-Version:        0.3.0+Version:        0.4.0 License:        GPL Copyright:      (c) Nicolas Pouillard Author:         Nicolas Pouillard@@ -18,7 +18,7 @@  executable csv2json     main-is: csv2json.hs-    Build-depends: base>=3&&<5, txt-sushi, json+    Build-depends: base>=3&&<5, txt-sushi, vector, bytestring, text, aeson     ghc-options: -Wall -Odph  executable csv-add-id
csv2json.hs view
@@ -1,5 +1,8 @@ import Data.Functor-import Text.JSON+import Data.Aeson+import qualified Data.Text as T+import qualified Data.Vector as V+import qualified Data.ByteString.Lazy.Char8 as L import Database.TxtSushi.FlatFile import System.Environment import Utils@@ -11,16 +14,17 @@     up with the delimitors of both CSV and JSON.  -} -csv2json :: FilePath -> IO JSValue+csv2json :: FilePath -> IO Value csv2json =-  fmap (JSArray . map (JSArray . map (JSString . toJSString))-                . parseTable csvFormat)+  fmap (Array . fmap (Array . fmap (String . T.pack) . V.fromList)+              . V.fromList+              . parseTable csvFormat)      . getContentsFromFileOrStdin  main :: IO ()-main = putStrLn . encode . mayJSArray+main = L.putStrLn . encode . mayArray    =<< mapM csv2json . addDefaultInput    =<< getArgs -  where mayJSArray [x] = x-        mayJSArray xs  = JSArray xs+  where mayArray [x] = x+        mayArray xs  = Array $ V.fromList xs