Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Derulo parses and renders JSON simply. It aims to provide an RFC 7159 compliant parser and renderer without incurring any dependencies. It is intended to be used either for learning or in situations where dependencies are unwanted. In normal usage, prefer a faster, more robust library like Aeson.
Derulo does not export any identifiers that conflict with the prelude and can be imported unqualified.
>>>
import Derulo
Use readJSON
to parse a String
into a JSON
value.
>>>
readJSON " null "
Just Null
Use showJSON
to render a JSON
value as a String
.
>>>
showJSON Null
"null"
- data JSON
- readJSON :: String -> Maybe JSON
- pJSON :: ReadP JSON
- pValue :: ReadP JSON
- pNull :: ReadP JSON
- pBoolean :: ReadP JSON
- pTrue :: ReadP JSON
- pFalse :: ReadP JSON
- pNumber :: ReadP JSON
- pInteger :: ReadP Integer
- pZero :: ReadP Integer
- pNonZero :: ReadP Integer
- pFraction :: ReadP (Integer, Integer)
- pPower :: ReadP Integer
- pString :: ReadP JSON
- pCharacter :: ReadP Char
- pLiteral :: ReadP Char
- pEscape :: ReadP Char
- pArray :: ReadP JSON
- pObject :: ReadP JSON
- pPair :: ReadP (String, JSON)
- showJSON :: JSON -> String
- sJSON :: JSON -> ShowS
- sNull :: ShowS
- sBoolean :: Bool -> ShowS
- sTrue :: ShowS
- sFalse :: ShowS
- sNumber :: Integer -> Integer -> ShowS
- sString :: String -> ShowS
- sCharacter :: Char -> ShowS
- sArray :: [JSON] -> ShowS
- sObject :: [(String, JSON)] -> ShowS
- sPair :: (String, JSON) -> ShowS
- fromBase :: Integer -> (Char -> Maybe Integer) -> String -> Maybe Integer
- fromDecimal :: String -> Maybe Integer
- fromDecimalDigit :: Char -> Maybe Integer
- fromHexadecimal :: String -> Maybe Integer
- fromHexadecimalDigit :: Char -> Maybe Integer
- isControl :: Char -> Bool
- isDecimalDigit :: Char -> Bool
- isHexadecimalDigit :: Char -> Bool
- isLiteral :: Char -> Bool
- isNonZeroDigit :: Char -> Bool
- isWhitespace :: Char -> Bool
- negateIf :: Bool -> Integer -> Integer
- pSymbol :: String -> ReadP ()
- pWhitespaces :: ReadP ()
- padLeft :: Integer -> a -> [a] -> [a]
- padRight :: Integer -> a -> [a] -> [a]
- runParser :: ReadP a -> String -> Maybe a
- sBetween :: ShowS -> ShowS -> (anything -> ShowS) -> anything -> ShowS
- sSeparated :: ShowS -> (element -> ShowS) -> [element] -> ShowS
- sSeparatedBetween :: ShowS -> ShowS -> ShowS -> (element -> ShowS) -> [element] -> ShowS
- toBase :: Integer -> (Integer -> Maybe Char) -> Integer -> String
- toBase' :: Integer -> (Integer -> Maybe Char) -> Integer -> String
- toHexadecimal :: Integer -> String
- toHexadecimalDigit :: Integer -> Maybe Char
Types
A JSON value as described by RFC 7159.
Parsing
readJSON :: String -> Maybe JSON Source #
Parses a string as JSON.
>>>
readJSON "null"
Just Null
>>>
readJSON "true"
Just (Boolean True)>>>
readJSON "false"
Just (Boolean False)
>>>
readJSON "0e0"
Just (Number 0 0)>>>
readJSON "12e34"
Just (Number 12 34)>>>
readJSON "-12e-34"
Just (Number (-12) (-34))
>>>
readJSON "\"\""
Just (String "")>>>
readJSON "\"js\""
Just (String "js")>>>
readJSON "\"\\\"\\\\\\b\\f\\n\\r\\t\""
Just (String "\"\\\b\f\n\r\t")>>>
readJSON "\"\\u001f\""
Just (String "\US")
>>>
readJSON "[]"
Just (Array [])>>>
readJSON "[null]"
Just (Array [Null])>>>
readJSON "[true,false]"
Just (Array [Boolean True,Boolean False])
>>>
readJSON "{}"
Just (Object [])>>>
readJSON "{\"\":null}"
Just (Object [("",Null)])>>>
readJSON "{\"t\":true,\"f\":false}"
Just (Object [("t",Boolean True),("f",Boolean False)])
pCharacter :: ReadP Char Source #
Rendering
showJSON :: JSON -> String Source #
Renders JSON as a string.
>>>
showJSON Null
"null"
>>>
showJSON (Boolean True)
"true">>>
showJSON (Boolean False)
"false"
>>>
showJSON (Number 0 0)
"0e0">>>
showJSON (Number 12 34)
"12e34">>>
showJSON (Number (-12) (-34))
"-12e-34"
>>>
showJSON (String "")
"\"\"">>>
showJSON (String "js")
"\"js\"">>>
showJSON (String "\"\\\b\f\n\r\t")
"\"\\\"\\\\\\b\\f\\n\\r\\t\"">>>
showJSON (String "\x1f")
"\"\\u001f\""
>>>
showJSON (Array [])
"[]">>>
showJSON (Array [Null])
"[null]">>>
showJSON (Array [Boolean True, Boolean False])
"[true,false]"
>>>
showJSON (Object [])
"{}">>>
showJSON (Object [("", Null)])
"{\"\":null}">>>
showJSON (Object [("t", Boolean True), ("f", Boolean False)])
"{\"t\":true,\"f\":false}"
sCharacter :: Char -> ShowS Source #
Helpers
isDecimalDigit :: Char -> Bool Source #
isHexadecimalDigit :: Char -> Bool Source #
isNonZeroDigit :: Char -> Bool Source #
isWhitespace :: Char -> Bool Source #
pWhitespaces :: ReadP () Source #
toHexadecimal :: Integer -> String Source #