ast-monad-json: A library for writing JSON

[ bsd3, language, library ] [ Propose Tags ]

[Skip to Readme]
Versions 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 2 made by MasatoMouri at Sat Mar 31 19:44:45 UTC 2018
Category Language
Home page https://github.com/mouri111/ast-monad-json#readme
Source repo head: git clone https://github.com/mouri111/ast-monad-json
Uploaded by MasatoMouri at Sat Apr 29 15:46:47 UTC 2017
Distributions NixOS:0.1.0.1
Downloads 682 total (12 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

Modules

[Index]

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

For package maintainers and hackage trustees


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}}