The ast-monad-json package

[ Tags: bsd3, language, library ] [ Propose Tags ]

[Skip to Readme]


Dependencies ast-monad, base (>=4.7 && <5), text [details]
License BSD3
Copyright 2017 Masato Mouri
Author Masato Mouri
Category Language
Home page
Source repository head: git clone
Uploaded Sat Apr 29 15:46:47 UTC 2017 by MasatoMouri
Updated Wed Sep 27 06:53:35 UTC 2017 by MasatoMouri to revision 1   [What is this?]
Distributions NixOS:
Downloads 638 total (280 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-04-29 [all 1 reports]
Hackage Matrix CI




Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Readme for ast-monad-json-

[back to package description]


A library for writing JSON


{-# LANGUAGE OverloadedStrings #-}
module Main where

import Language.ASTMonad
import Language.ASTMonad.Json
import Language.ASTMonad.Json.Renderer
import qualified Data.Text.Lazy.IO as TL
import qualified Data.Text.Lazy.Builder as TB

data Parameter = Parameter { px :: Int, py :: Int }

jsonCode :: Json Parameter
jsonCode = do
  "id1" `is` "val1"
  "id2" `is` "val2"
  "flag" `isBool` True
  "point" `isArray` do
    x <- getParam px
    y <- getParam py
    "px" `isNum` x
    "py" `isNum` y

main :: IO ()
main = do
  let param = Parameter { px = 123, py = 456 }
  TL.putStrLn $ TB.toLazyText $ renderJson $ buildAST jsonCode param JsonEnvironment

The execution result of the above code is