@hackage json5hs0.1.3.1

Serialising to and from JSON5

json5hs: Serialising to and from JSON5

Hackage Build


This library provides a parser and pretty printer for converting between Haskell values and JSON5.

Example

ghci> import Text.JSON5
ghci> encode [("key1",1),("key2",2)]
"[[\"key1\",1],[\"key2\",2]]"

ghci> import Text.JSON5.String (runGetJSON)
ghci> input <- getLine 
{'singleQuotes': 0xabcde, pos: +3, infnan: +Infinity, escape: "\t\u1234", trailing-comma: ['here',], }
ghci> runGetJSON readJSValue input
Right (JSObject (JSONObject {fromJSObject = [("singleQuotes",JSNumber (JSRational (703710 % 1))),("pos",JSNumber (JSRational (3 % 1))),("infnan",JSNumber (JSInfNaN Infinity)),("escape",JSString (JSONString {fromJSString = "\t\4660"})),("trailing-comma",JSArray [JSString (JSONString {fromJSString = "here"})])]}))

ghci> import Text.JSON5.Pretty
ghci> ppJSValue $ makeObj [("key1", JSString $ toJSString "value1"), ("key2", JSArray [JSNull, JSBool True])]
{"key1": "value1", "key2": [null, true]}

ghci> import Text.JSON5.Generic
ghci> ppJSValue $ toJSON $ Just [2,1,4]
{"Just": [2, 1, 4]}
ghci> fromJSON (JSString $ toJSString "string") :: Result String 
Ok "string"
  • Installation

  • Dependencies (8)

  • Dependents (0)

  • Package Flags

      split-base
       (on by default)

      Use the new split base package.

      pretty
       (on by default)

      Add support for using pretty printing combinators.

      generic
       (on by default)

      Add support for generic encoder.

      mapdict
       (off by default)

      Encode Haskell maps as JSON dicts