ast-monad-json: A library for writing JSON

[ bsd3, language, library ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

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

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1
Dependencies ast-monad, base (>=4.7 && <5), text [details]
License BSD-3-Clause
Copyright 2017 Masato Mouri
Author Masato Mouri
Maintainer 8128jp@gmail.com
Revised Revision 3 made by MasatoMouri at 2020-12-05T06:13:58Z
Category Language
Home page https://github.com/spica314/ast-monad-json#readme
Source repo head: git clone https://github.com/spica314/ast-monad-json
Uploaded by MasatoMouri at 2017-04-29T15:46:47Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1956 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-04-29 [all 1 reports]

Readme for ast-monad-json-0.1.0.1

[back to package description]

ast-monad-json

A library for writing JSON

Example

{-# 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

{"id1":"val1","id2":"val2","flag":true,"point":{"px":123,"py":456}}