on master help sign in
Add in json2yaml
commit1dad54752bad81670955b8549ec9f024a5ff6ec3 authorMichael Snoyman <michael@snoyman.com> dateThu 20 Mar 2014, 10:20 (13 years ago) parent26c86ba
2 files changed+40−2
exe/json2yaml.hs+25 yaml.cabal+15−2
exe/json2yaml.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# LANGUAGE MultiParamTypeClasses #-}
2+{-# LANGUAGE FlexibleInstances #-}
3+import System.Environment (getArgs)
4+import qualified Data.Aeson as J
5+import qualified Data.Yaml as Y
6+import Control.Monad (when)
7+import qualified Data.ByteString as S
8+import qualified Data.ByteString.Lazy as L
9+import Control.Applicative ((<$>))
10+
11+main :: IO ()
12+main = do
13+ args <- getArgs
14+ when (length args > 2) $ error "Usage: json2yaml [in] [out]"
15+ let (input:output:_) = args ++ repeat "-"
16+ mval <- J.decode <$>
17+ case input of
18+ "-" -> L.getContents
19+ _ -> L.readFile input
20+ case mval of
21+ Nothing -> error "Invalid input JSON"
22+ Just val -> do
23+ case output of
24+ "-" -> S.putStr $ Y.encode (val :: Y.Value)
25+ _ -> Y.encodeFile output val
yaml.cabal+15−2
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.8.7.2
2+version: 0.8.8
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -30,7 +30,7 @@ extra-source-files: c/helper.h,
3030 test/json.yaml
3131
3232flag no-exe
33− description: don't install the yaml2json executable
33+ description: don't install the yaml2json or json2yaml executables
3434 default: False
3535
3636flag system-libyaml
@@ -84,6 +84,19 @@ executable yaml2json
8484 , bytestring >= 0.9.1.4
8585 , aeson >= 0.5
8686
87+executable json2yaml
88+ if flag(no-exe)
89+ Buildable: False
90+ else
91+ Buildable: True
92+
93+ hs-source-dirs: exe
94+ main-is: json2yaml.hs
95+ build-depends: base >= 4 && < 5
96+ , yaml
97+ , bytestring >= 0.9.1.4
98+ , aeson >= 0.5
99+
87100
88101test-suite test
89102 type: exitcode-stdio-1.0