Skip to content

Commit

Permalink
Add in json2yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Mar 20, 2014
1 parent 26c86ba commit 1dad547
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
25 changes: 25 additions & 0 deletions exe/json2yaml.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
import System.Environment (getArgs)
import qualified Data.Aeson as J
import qualified Data.Yaml as Y
import Control.Monad (when)
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import Control.Applicative ((<$>))

main :: IO ()
main = do
args <- getArgs
when (length args > 2) $ error "Usage: json2yaml [in] [out]"
let (input:output:_) = args ++ repeat "-"
mval <- J.decode <$>
case input of
"-" -> L.getContents
_ -> L.readFile input
case mval of
Nothing -> error "Invalid input JSON"
Just val -> do
case output of
"-" -> S.putStr $ Y.encode (val :: Y.Value)
_ -> Y.encodeFile output val
17 changes: 15 additions & 2 deletions yaml.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yaml
version: 0.8.7.2
version: 0.8.8
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
Expand Down Expand Up @@ -30,7 +30,7 @@ extra-source-files: c/helper.h,
test/json.yaml

flag no-exe
description: don't install the yaml2json executable
description: don't install the yaml2json or json2yaml executables
default: False

flag system-libyaml
Expand Down Expand Up @@ -84,6 +84,19 @@ executable yaml2json
, bytestring >= 0.9.1.4
, aeson >= 0.5

executable json2yaml
if flag(no-exe)
Buildable: False
else
Buildable: True

hs-source-dirs: exe
main-is: json2yaml.hs
build-depends: base >= 4 && < 5
, yaml
, bytestring >= 0.9.1.4
, aeson >= 0.5


test-suite test
type: exitcode-stdio-1.0
Expand Down

0 comments on commit 1dad547

Please sign in to comment.