ast-monad-json: A library for writing JSON

[ bsd3, language, library ] [ Propose Tags ]

[Skip to Readme]
Versions [RSS] [faq],
Dependencies ast-monad, base (>=4.7 && <5), text [details]
License BSD-3-Clause
Copyright 2017 Masato Mouri
Author Masato Mouri
Revised Revision 3 made by MasatoMouri at 2020-12-05T06:13:58Z
Category Language
Home page
Source repo head: git clone
Uploaded by MasatoMouri at 2017-04-29T15:46:47Z
Distributions NixOS:
Downloads 1738 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2017-04-29 [all 1 reports]




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