The tyro package

[Tags:bsd3, library, test]

A library for deriving JSON parsers (using Aeson) by indicating JSON structure at the type level.


[Skip to Readme]

Properties

Versions 0.1.1.0, 0.1.1.1, 0.2.0.0
Dependencies aeson, base (>=4.9 && <5), bytestring, protolude (>=0.1.6 && <0.2), reflection, singletons, text [details]
License BSD3
Copyright 2017 Richard Lupton
Author Richard Lupton
Maintainer example@example.com
Category Text, Web, JSON
Home page https://github.com/rlupton20/tyro#readme
Source repository head: git clone https://github.com/rlupton20/tyro
Uploaded Wed Apr 5 22:34:47 UTC 2017 by rlupton20
Distributions NixOS:0.2.0.0
Downloads 116 total (2 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-04-05 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for tyro

Readme for tyro-0.2.0.0

tyro

tyro is a dependently type JSON parsing library, that provides a quick way to create JSON parsers by deriving them from a type level description of the position of the value to be obtained.

Examples

Type driven interface

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}

import Data.Tyro
import Data.Aeson (decode)
import qualified Data.ByteString.Lazy as B

json = "{\"key1\":[{\"key2\":41},{\"key2\":42}]}" :: B.ByteString

-- Extract [41, 42] inside the Tyro types
parsed = decode json :: Maybe ("key1" >%> List ("key2" >%> Extract Integer))

-- We can dispose of the types using unwrap
values :: Maybe [Integer]
values = fmap unwrap parsed

Value driven interface

{-# LANGUAGE OverloadedStrings #-}
import Data.Tyro

json = "{\"key1\": {\"key2\" :  [41, 42]}}" :: B.ByteString

-- Extract [41, 42] inside the JSON
parsed = json %%> "key1" >%> "key2" >%> extract :: Maybe [Integer]