3**Note**: This is a fork of [simple-json](https://github.com/justinwoo/purescript-simple-json) ([MIT Licence](./LICENSE/simple-json.LICENSE)).
7* [migrate from `simple-json`](#migrate-from-purescript-simple-json)
12import Yoga.JSON as JSON
16 JSON.writeJSON { first_name: "Lola", last_name: "Flores" }
19Check out the tests for how to encode/decode increasingly complex types.
21## Migrate from `purescript-simple-json`
23`purescript-yoga-json` is almost (read below if you use variants) a drop-in replacement for `purescript-simple-json`. Just change the imports from `Simple.JSON` to `Yoga.JSON`.
25## Additions over `simple-json`
28yoga-json will actually report multiple errors at once in the case of records, objects, and arrays.
29There's also a way to make errors more readable with `renderHumanError`:
30(e.g. `Must provide a value of type 'Int' instead of 'Object' at $.a.b.c.d[1]`)
34There is an inbuilt codec for `Tuple`s thanks to @ursi
35`yoga-json` represents tuples as arrays in JSON.
38There is an inbuilt codec for `Either`s.
39`yoga-json` represents eithers as objects with a `type` and a `value` tag in JSON.
41### JSDate and DateTime
42Both are encoded as ISO8601 strings as spat out by `JSDate.toISOString`.
45It includes @justinwoo's codecs for en- and decoding generics inspired by
46[simple-json-generics](https://github.com/justinwoo/purescript-simple-json-generics)
48It is possible to customise the representation of enums, tagged sum types, and untagged sum types via options.
51There is an inbuilt codec for `BigInt`. Writing a `BigInt` however will result in a String. This is a current limitation of JavaScript and the only way around it - it seems - is writing your own JSON.stringify method (which is out of scope of this project).
53## Differences to `simple-json`
56If you want to emulate `simple-json`'s format you may use the newtype `TaggedVariant`
59type YourVariantRow = ( a :: Int, b :: String )
60type YourVariant = Variant YourVariantRow
62x = inj (Proxy :: Proxy "a") 5
63-- encoded = writeJSON x
64-- ^ Let's say you had this before
66encoded = writeJSON (TaggedVariant "type" "value" x)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list