I’m looking for a library to help me implement some custom JSON serialization for Records (need to capitalize the keys, long story). It seems like there are two libraries with extremely confusingly similar names which might support this called “purescript-codec-argonaut” and “purescript-argonaut-codecs”. There’s almost no documentation for the former one. Why are there two libraries with almost the same name, and what is the difference between them?
argonaut-codecs
is bundled as part of argonaut
, so when you ask for argonaut
, you get that as well. It contains typeclasses and instances for encoding/decoding Json
. purescript-codec is a general purpose set of types for writing bidirectional/round-tripping codecs, but isn’t tied to any particular format. codec-argonaut
is a library for decoding Json
(from argonaut-core
) with codec
. The main purpose of codec-argonaut
is to aid writing manual codecs (vs using typeclasses). For example, with a single record definition, you can both encode and decode something of that shape.
type MyRecord =
{ foo :: String
, bar :: Int
, baz :: Boolean
}
codec :: JsonCodec MyRecord
codec = record
{ foo: string
, bar: int
, baz: boolean
}
test1 = encode codec { foo: "hello", bar: 42, baz: true }
test2 = decode codec test1
This can be helpful when you need to tightly control compatibility, or you want to write things that don’t match the default implementations of typeclasses (like handling Maybe
).
Ah, cool! Thanks a lot!
Although it looks like codec-argonaut
is not in the default package-set. Might not be updated for 0.13 yet.
In the absence of proper docs still, I added a couple of sentences to the readme that tries to explain the differences at a high level, and the motivation for it.
I probably should have chosen a different name for the library though…