JSON: Difference between revisions
Content added Content deleted
No edit summary |
(Adding Haskell) |
||
Line 102: | Line 102: | ||
"ocean":{"water":["cold","blue"]}} |
"ocean":{"water":["cold","blue"]}} |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
|||
<lang Haskell> |
|||
{-# LANGUAGE OverloadedStrings #-} |
|||
import Data.Aeson |
|||
import Data.Attoparsec (parseOnly) |
|||
import Data.Text |
|||
import qualified Data.ByteString.Lazy.Char8 as B |
|||
import qualified Data.ByteString.Char8 as S |
|||
testdoc = object [ |
|||
"foo" .= (1 :: Int), |
|||
"bar" .= ([1.3, 1.6, 1.9] :: [Double]), |
|||
"baz" .= ("some string" :: Text), |
|||
"other" .= object [ |
|||
"yes" .= ("sir" :: Text) |
|||
] |
|||
] |
|||
main = do |
|||
let out = encode testdoc |
|||
B.putStrLn out |
|||
case parseOnly json (S.concat $ B.toChunks out) of |
|||
Left e -> error $ "strange error re-parsing json: " ++ (show e) |
|||
Right v -> print v |
|||
</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |