Package

purescript-yoga-json

Repository
rowtype-yoga/purescript-yoga-json
License
MIT
Uploaded by
i-am-the-slime
Published on
2022-06-11T19:13:29Z

Note: This is a fork simple-json (MIT Licence).

Table of Contents

Usage

import Yoga.JSON as JSON

serialised :: String
serialised =
  JSON.writeJSON { first_name: "Lola", last_name: "Flores" }

Check out the tests for how to encode/decode increasingly complex types.

Migrate from purescript-simple-json

purescript-yoga-json is a drop-in replacement for purescript-simple-json. Just change the imports from Simple.JSON to Yoga.JSON.

Differences to simple-json

There is an inbuilt codec for Tuples thanks to @ursi

It includes @justinwoo's codecs for en- and decoding generics inspired by simple-json-generics

💣 The Variant Codec is different

If you want to emulate simple-json's format you may use the newtype TaggedVariant

type YourVariantRow = ( a :: Int, b :: String )
type YourVariant = Variant YourVariantRow
x :: YourVariant
x = inj (Proxy :: Proxy "a") 5
-- encoded = writeJSON x
-- ^ Let's say you had this before
-- You can now do:
encoded = writeJSON (TaggedVariant "type" "value" x)