Copyright | (c) Jonathan Kochems 2015 |
---|---|
License | BSD-3 |
Maintainer | jonathan.kochems@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Text.JSON.Permissive
Description
This module extends Text.JSON to enable the decoding of strings containing literal JS objects. In particular, it relaxes the restriction that fields in JSON objects must be strings.
For example:
JSON conformant: literal JS object: { "foo" : "bar" } { foo : "bar" }
- decodePermissive :: String -> Result (JSObject JSValue)
- get_fields :: JSObject a -> [String]
Documentation
decodePermissive :: String -> Result (JSObject JSValue) Source
decodes a string encoding a JSON object in a relaxed fashion
decode "{ foo : \"bar\" }" Error "Malformed JSON: expecting string: foo : \"b" decodePermissive "{ foo : \"bar\" }" == Ok $ toJSObject [("foo", JSString $ toJSString "bar")] decodePermissive "{ \"foo\" : \"bar\" }" == Ok $ toJSObject [("foo", JSString $ toJSString "bar")]
get_fields :: JSObject a -> [String] Source
returns the list of fields of a JSON Object
do obj <- decodePermissive "{ foo : \"bar\", fooz : \"baz\" }" return $ get_fields obj == Ok ["foo", "fooz"]
do obj <- decodePermissive "{ foo : \"bar\", fooz : \"baz\" }" return $ get_field obj $ head $ get_fields obj == Ok (Just $ JSString $ toJSString "bar" )