-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters