The ast-monad-json package

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

[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1
Dependencies ast-monad, base (>=4.7 && <5), text [details]
License BSD3
Copyright 2017 Masato Mouri
Author Masato Mouri
Maintainer mkdagjp@gmail.com
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 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:0.1.0.1
Downloads 654 total (16 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}}