json5hs: Serialising to and from JSON5

[ bsd3, json5, library, text, web ] [ Propose Tags ] [ Report a vulnerability ]

The JSON5 Data Interchange Format (JSON5) is a superset of JSON that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from ECMAScript 5.1.

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


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
split-base

Use the new split base package.

Enabled
pretty

Add support for using pretty printing combinators.

Enabled
generic

Add support for generic encoder.

Enabled
mapdict

Encode Haskell maps as JSON dicts

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.2.0, 0.1.2.1, 0.1.2.2, 0.1.3.0, 0.1.3.1 (info)
Dependencies array, base, bytestring, containers, mtl, pretty, syb (>=0.3.3), text [details]
License BSD-3-Clause
Copyright 2019 Yang X. Nan
Author Yang X. Nan
Maintainer yxnan@pm.me
Category Web, Text, JSON5
Source repo head: git clone https://github.com/typowritter/json5hs.git
Uploaded by sakamitz at 2020-09-01T15:00:30Z
Distributions NixOS:0.1.3.1
Downloads 1995 total (5 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for json5hs-0.1.3.1

[back to package description]

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"