json-tools 0.2.0 → 0.2.1
raw patch · 3 files changed
+19/−16 lines, 3 files
Files
- json-select.hs +1/−1
- json-tools.cabal +2/−2
- json-unlines.hs +16/−13
json-select.hs view
@@ -118,7 +118,7 @@ ,"path ::= # A path can be empty" ," | '/' <segment> <path> # Chain a path segment and a path" ,""- ,"segement ::= '\"' <char>* '\"' # Access the object/mapping at the given key"+ ,"segement ::= '\"' <char>* '\"' # Access the object/mapping at the given key" ," | [ '0' - '9' ]* # Access the array/sequence at the given index" ," | '*' # Keep all children of the given node (requires -m)" ,""
json-tools.cabal view
@@ -1,6 +1,6 @@ Name: json-tools Cabal-Version: >=1.6-Version: 0.2.0+Version: 0.2.1 License: BSD3 License-File: LICENSE Copyright: (c) Nicolas Pouillard@@ -44,7 +44,7 @@ executable json-unlines main-is: json-unlines.hs- Build-depends: base>=3&&<5, AttoJson, bytestring+ Build-depends: base>=3&&<5, bytestring ghc-options: -Wall -Odph executable json-wrap
json-unlines.hs view
@@ -1,15 +1,18 @@-import Text.JSON.AttoJSON-import qualified Data.ByteString.Char8 as S-import Control.Arrow (second)+{-# LANGUAGE OverloadedStrings #-}+import qualified Data.ByteString.Char8 as L+import System.Environment +-- utility function+getAllContents :: IO L.ByteString+getAllContents =+ do args <- getArgs+ if null args+ then L.getContents+ else fmap L.concat . mapM file $ args+ where file "-" = L.getContents+ file xs = L.readFile xs+ main :: IO ()-main = S.putStr . showJSON -- printing the output- . JSArray -- building the result- . map err -- error handling- . map (second parseJSON) -- parsing a line- . zip [1::Integer ..] -- number lines- . S.lines -- cut into a list of lines- =<< S.getContents -- reading the input- where- err (ln, Left msg) = error $ "JSON parsing: (line "++show ln++"): "++msg- err (_, Right x) = x+main = do+ L.putStrLn . L.cons '[' . L.intercalate "\n," . L.lines =<< getAllContents+ L.putStrLn "]"