Uploaded at Oct 10 16:58:37 2024 (UTC)
Succesfully tested at Oct 11 04:10:24 2024

Curry Package json

JSON

This package provides data types, a parser and a pretty printer for JSON.

Representing JSON values in Curry

A JSON value can be a primitive, i.e. true, false, null, a string or a number, an array of JSON values or an object mapping strings to JSON values. In Curry, a JSON value is represented by the data type JValue from the JSON.Data module:

data JValue = JTrue
            | JFalse
            | JNull
            | JString String
            | JNumber Float
            | JArray [JValue]
            | JObject [(String, JValue)]

Parsing JSON strings

parseJSON from JSON.Parser can be used to parse a JSON string into a JValue:

> parseJSON "{ \"hello\": [\"world\", \"kiel\"] }"
Just (JObject [("hello", JArray [JString "world", JString "kiel"])])

Printing JSON strings

ppJSON from JSON.Pretty will turn a JValue into a pretty printed string. If you want more control over the layout of the resulting string, you can use ppJValue from the same value to obtain a Doc for Curry’s Pretty module from a JValue.

Converting to and from JSON

The module JSON.Convert defines a defines a type class ConvertJSON and various instances for standard types to convert Curry values to JSON values and vice versa. As apparent from these instance definitions, it is quite easy to define instances for other user-defined data types.


Download

Checkout with CPM:
cypm checkout json 3.0.0
Package source:
json-3.0.0.tar.gz [browse]
Source repository:
https://github.com/curry-packages/json.git