json-clean
Package info
-
Homepage
gitlab.com/eldesh/json-clean -
Latest version
0.3.0, 7 months ago -
Maintainer
takayuki goto -
License
BSD-2-Clause
Description
A json serializer/deserializer library.
Readme
# Json Serialize/Deserialize Library for Clean
This library provides JSON serializer and deserializer for Clean.
Main functions are provides from the `Data.Json` module.
## JSON constructs
JSON data structures are represented by the `JValue` type.
```clean
:: JValue = JNull
| JBool Bool
| JString UString
| JInteger JInt
| JFloat JReal
| JArray [JValue]
| JObject [(UString, JValue)]
```
`JNull` represent `null`.
```clean
toString JNull == "null"
```
`JBool` represent `true` and `false`.
```clean
toString (JBool True) == "true"
```
`JString` represent JSON String.
Where the type of argument `UString` is represent Unicode string imported from `Text.Unicode`.
```clean
str :: UString
str = fromString "json string"
toString (JString str) == "json string"
```
`JInteger` takes `JInt` as value of integer.
The `JInt` is an opaque type for integers with exponents, and the value is constructed with `jint`.
```clean
jint :: Int (?Int) -> JValue
toString (jint 5 ?None ) == "5"
toString (jint 2 (?Just 10)) == "2e10"
```
Similarly, `JFloat` is an opaque type for floating point numbers with exponents, and the value is constructed with `jreal`.
```clean
jreal :: Real (?Int) -> JValue
toString (jreal 5.2 ?None ) == "5.2"
toString (jreal 3.1 (?Just (~10))) == "3.1e-10"
```
`JArray` represented JSON array.
```clean
toString (JArray [JNull, JBool True]) == "[null,true]"
```
`JObject` represented JSON object.
```clean
f1 :: UString
f1 = fromString "field1"
f2 :: UString
f2 = fromString "field2"
toString (JObject [(f1, JBool True), (f2, jint 5 ?None)]) == "{\"field1\":true, \"field2\":5}"
```
## Deserialize
Use `parseJSONString` to parse a string as JSON.
```clean
parseJSONString :: String -> ?JValue
```
Or to parse utf8 string, you can use `parseJSONUTF8` as follows.
```clean
parseJSONUTF8 :: UTF8 -> ?JValue
```
Changelog
# Change Log
## [Unreleased]
## [0.3.0] - 2024-12-09
### Added
- added `instance (==) JValue`
- added `parseJSONUTF8` to parse utf8 string
### Changed
- renamed `parseJSON` to `parseJSONString`
### Fixed
- fixed `jsonChar` to read UTF8 strings correctly
- fixed normalization algorithm for values of type `JInt`
## [0.2.0] - 2024-11-14
## [0.1.0] - 2024-11-14
### Added
- type `JValue` represents JSON text
- class `ToJson` and it's instances
- `parseJSON` function parses input string as a JSON text
Versions
-
0.3.0 latest 7 months ago
Dependencies: base =3.0.0; category-theory =1.1.1; text =2.0.1.
Targets: linux-x64.
-
0.2.0 latest 0.2 8 months ago
Dependencies: base =3.0.0; category-theory =1.1.1; text =2.0.1.
Targets: linux-x64.
-
0.1.0 latest 0.1 8 months ago
Dependencies: base =3.0.0; category-theory =1.1.1; text =2.0.1.
Targets: linux-x64.