git.iko.soy/rowtype-yoga/purescript-yoga-json
on v2.0.0 help sign in
44 lines 1.4 kB history raw
1# ๐Ÿ๐Ÿ‘‘ purescript-yoga-json
3**Note**: This is a fork [simple-json](https://github.com/justinwoo/purescript-simple-json) ([MIT Licence](./LICENSE/simple-json.LICENSE)).
5## Table of Contents
6* [usage](#usage)
7* [migrate from `simple-json`](#migrate-from-purescript-simple-json)
9## Usage
11```purescript
12import Yoga.JSON as JSON
14serialised :: String
15serialised =
16 JSON.writeJSON { first_name: "Lola", last_name: "Flores" }
17```
19Check out the tests for how to encode/decode increasingly complex types.
21## Migrate from `purescript-simple-json`
23`purescript-yoga-json` is a drop-in replacement for `purescript-simple-json`. Just change the imports from `Simple.JSON` to `Yoga.JSON`.
25## Differences to `simple-json`
27There is an inbuilt codec for `Tuple`s thanks to @ursi
29It includes @justinwoo's codecs for en- and decoding generics inspired by
30[simple-json-generics](https://github.com/justinwoo/purescript-simple-json-generics)
32### ๐Ÿ’ฃ The Variant Codec is different
33If you want to emulate `simple-json`'s format you may use the newtype `TaggedVariant`
35```purescript
36type YourVariantRow = ( a :: Int, b :: String )
37type YourVariant = Variant YourVariantRow
38x :: YourVariant
39x = inj (Proxy :: Proxy "a") 5
40-- encoded = writeJSON x
41-- ^ Let's say you had this before
42-- You can now do:
43encoded = writeJSON (TaggedVariant "type" "value" x)
44```