| Copyright | (c) Jonathan Kochems 2015 |
|---|---|
| License | BSD-3 |
| Maintainer | jonathan.kochems@gmail.com |
| Stability | experimental |
| Portability | nonportable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Text.JSON.NonStrict
Description
This module extends Text.JSON to enable the decoding of strings containing literal JS objects. In particular, it relaxes the restrictions that fields in JSON objects must be strings.
For example:
JSON conformant: literal JS object:
{ "foo" : "bar" } { foo : "bar" }- decodeNonStrict :: String -> Result (JSObject JSValue)
- get_fields :: JSObject a -> [String]
Documentation
decodeNonStrict :: 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"
decodeNonStrict "{ foo : \"bar\" }" == Ok $ toJSObject [("foo", JSString $ toJSString "bar")]
decodeNonStrict "{ \"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 <- decodeNonStrict "{ foo : \"bar\", fooz : \"baz\" }"
return $ get_fields obj == Ok ["foo", "fooz"]do obj <- decodeNonStrict "{ foo : \"bar\", fooz : \"baz\" }"
return $ get_field obj $ head $ get_fields obj == Ok (Just $ JSString $ toJSString "bar" )