Skip to content

Commit

Permalink
update Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yxnan committed Jul 26, 2019
1 parent 135ee8e commit 3bb063a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ between Haskell values and JSON5.
## Example

```haskell
ghci> import qualified Text.JSON5 as J
ghci> J.encode [("key1",1),("key2",2)]
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 J.readJSValue input
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> ppJSValue (JSObject (JSONObject [("key1",JSString (JSONString "string")),("key2",JSNumber (JSRational 42)),("key3",JSArray [JSBool True,JSNull])]))
{"key1": "string", "key2": 42, "key3": [true, null]}
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"
```

2 changes: 1 addition & 1 deletion json5hs.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json5hs
version: 0.1.2
version: 0.1.2.2
synopsis: Serialising to and from JSON5
description:
The JSON5 Data Interchange Format (JSON5) is a superset of JSON
Expand Down

0 comments on commit 3bb063a

Please sign in to comment.