dead-simple-json-0.1.2: Dead simple JSON parser, with some Template Haskell sugar.

MaintainerJulian Fleischer <>
Safe HaskellNone




A simple approach for parsing JSON.

To read JSON data use read. To print JSON data use show:

 let jsonData = read "[1,2,4,8,16]" :: JSON
 putStrLn $ show jsonData

You can query json data using ?. Querying implies conversion, therefor you may need to specify the result type:

 let jsonData = read "{\"seven\": 7, \"nine\": [1,2,4,8,16]}"
 print $ (jsonData ? "nine[3]" :: Int)

For tighter control use parse. A more convenient way for creating JSON objects in source code or querying JSON data, is using Template Haskell. See Text.SimpleJSON.TH.

The recommended way for importing this module is importing it qualified, like so:

 import qualified Text.SimpleJSON as JSON
 import Text.SimpleJSON (JSON)


Parsing strings

parse :: String -> Either ParseError JSONSource

Parse a String for JSON data or return a ParseError.

parse' :: String -> Maybe ValueSource

Parses a top-level JSON object, returning Just a Value or Nothing.

parseM :: Monad m => String -> m ValueSource

Purely Monadic version of parse'.

Basic data types

data Value Source

A JSON value.


String String

A JSON String, represented as ordinary Haskell String.

Number !Integer !Integer

A JSON Number, represented by two Integers in exponontial form. Number n e is the same as {n}e{exp}, that is n * 10 ^ e. This allows for arbitrary precision fixed point rationals. See Convert for easy conversions.

Object (Map String Value)

A JSON Object, represented as Map.

Array (Vector Value)

A JSON Array, represented as Vector of Values.






Null (void, unit, ()).

data JSON Source

A top-level JSON object.

Merely a wrapper that ensures that no other Values but Array and Object reside at the top-level.

Querying json data

(?) :: Convert a => JSON -> String -> aSource

top :: JSON -> ValueSource

Unwraps a top-level JSON object to a Value.

Conversion to and from