Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-simple-json
A simple Purescript JSON library that uses types automatically
https://github.com/justinwoo/purescript-simple-json
json purescript type-level
Last synced: 13 days ago
JSON representation
A simple Purescript JSON library that uses types automatically
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-simple-json
- Owner: justinwoo
- License: mit
- Created: 2017-07-13T18:20:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-02T13:18:40.000Z (over 1 year ago)
- Last Synced: 2024-04-22T18:26:39.482Z (7 months ago)
- Topics: json, purescript, type-level
- Language: PureScript
- Homepage: http://purescript-simple-json.readthedocs.io
- Size: 130 KB
- Stars: 134
- Watchers: 6
- Forks: 46
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-purescript - purescript-simple-json - Json encoding and decoding through Generics. (Json Serialization)
README
# PureScript-Simple-JSON
![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/justinwoo/purescript-simple-json/ci.yml?branch=master&style=flat-square&logo=github)
[](https://readthedocs.org/projects/purescript-simple-json/badge/?version=latest)A simple Foreign/JSON library based on the Purescript's RowToList feature.
## Quickstart
Get going quickly with the Quickstart section of the guide:
You may also be interested in this presentation about how Simple-JSON works well with PureScript-Record: . Note that the slides are based on an older version of the library and on PureScript 0.11.6, and it is not necessary to understand these slides to get started.
## Usage
In brief:
```purs
type MyJSON =
{ apple :: String
, banana :: Int
, cherry :: Maybe Boolean
}
decodeToMyJSON :: String -> Either (NonEmptyList ForeignError) MyJSON
decodeToMyJSON = SimpleJSON.readJSON
```See the [API Docs](https://pursuit.purescript.org/packages/purescript-simple-json/) or the [tests](test/Main.purs) for usage.
There is also a guide for how to use this library on [Read the Docs](https://purescript-simple-json.readthedocs.io/en/latest/).
## Warning: `Maybe`
This library will decode `undefined` and `null` as `Nothing` and write `Nothing` as `undefined`. Please use the `Nullable` type if you'd like to read and write `null` instead. Please take caution when using `Maybe` as this default may not be what you want.
## FAQ
### How do I use this with Affjax?
Please see this page in the guide:
### How do I change how some fields of my JSON objects are read?
Please see this page in the guide:
### How do I work with `data` Types?
Please see this page in the guide:
### Why won't you accept my Pull Request?
Please read this appeal from another open source author:
### How should I actually use this library?
James Brock has informed me that people still do not understand that this library should be used not as a library. If you do not like any of the behavior in this library or would like to opt out of some behaviors, you should copy this library into your own codebase. Please see that this libraries does not actually contain many lines of code and you should be able to learn how to construct this library from scratch with a few days of reading.