AttoJson-0.5.10: Simple lightweight JSON parser, generator & manipulator based on ByteString




Class and Data-Types for JSON Value

data JSValue Source

Data types for JSON value.



JSON String

JSNumber Rational

JSON Number

JSObject (Map ByteString JSValue)

JSON Object

JSArray [JSValue]

JSON Array

JSBool !Bool




class JSON a whereSource

Type Class for the value that can be converted from/into JSValue.


fromJSON :: JSValue -> Maybe aSource

Decode from JSValue

toJSON :: a -> JSValueSource

Encode into JSValue


Parsing & Printing

parseJSON :: ByteString -> Either String JSValueSource

Parse JSON source. Returns JSValue (Right) if succeed, Returns Left if failed.

The input string should be UTF8-encoded. Unicode escapes (e.g. "\u266B") are encoded in UTF8 by the parser, so incompatibilities will arise if you try to use AttoJSON with other encodings.

showJSON :: JSValue -> ByteStringSource

Print JSValue as JSON source (not pretty).

The output string will be in UTF8 (provided the JSValue was constructed with UTF8 strings). Only characters that have to be escaped (control characters, \, and ") will be escaped.

showJSON' :: JSValue -> ByteStringSource

Same as showJSON, but escape non-ASCII characters as well.

Manipulating Objects

lookup :: JSON a => ByteString -> JSValue -> Maybe aSource

Get the value for field in Object and decode it.

getField :: JSON a => ByteString -> JSValue -> Maybe aSource

DEPRECATED: Alias of lookup. Use lookup.

findWithDefault :: JSON a => a -> ByteString -> JSValue -> aSource

lookup with default value.

lookupDeep :: JSON a => [ByteString] -> JSValue -> Maybe aSource

Same as lookup but it can process nested Object. ex:

   lookupDeep ["user", "name"] (JSObject [("user", JSObject [("name", JSString "hoge")])]) == Just "hoge"

getFields :: JSON a => [ByteString] -> JSValue -> Maybe aSource

DEPRECATED: Alias of lookupDeep

findDeepWithDefault :: JSON a => a -> [ByteString] -> JSValue -> aSource

getFields with default value.

updateField :: JSON a => ByteString -> a -> JSValue -> JSValueSource

Update or Insert the value for field in Object.