EncodeJson
and DecodeJson
classes and instances, useful combinators for encoding and decoding Json
values.
bower install purescript-argonaut-codecs
Module documentation is published on Pursuit.
Using purescript-argonaut-core we can build a simple Json
object:
someObject =
let
objects =
[ jsonSingletonObject "bar" (fromString "a")
, jsonSingletonObject "bar" (fromString "b")
]
in
fromObject $ Object.fromFoldable [ Tuple "foo" (fromArray objects) ]
The decodeJson
and .?
functions provided in this module make it straightforward to interrogate the Json
object:
main =
log $ show $ getBars someObject
getBars :: Json -> Either String (Array String)
getBars json = do
obj <- decodeJson json
foo <- obj .? "foo"
for foo \itemJson -> do
itemObj <- decodeJson itemJson
itemObj .? "bar"
Read the contribution guidelines to get started and see helpful related resources.