JSON serialization using Argonaut.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github Update issue_template.md Aug 27, 2018
src/Data/Argonaut Removed the toNonEmpty function. Now using List.uncons and Array.unco… Nov 15, 2018
test/Test Removed the toNonEmpty function. Now using List.uncons and Array.unco… Nov 15, 2018
.gitignore Add contribution guidelines, issue templates, and pull request templa… Jun 21, 2018
.travis.yml fetch latest purs for travis Jun 4, 2018
LICENSE
README.md Merge branch 'master' into master Nov 11, 2018
bower.json
package-lock.json Add contribution guidelines, issue templates, and pull request templa… Jun 21, 2018
package.json Add contribution guidelines, issue templates, and pull request templa… Jun 21, 2018

README.md

purescript-argonaut-codecs

Latest release Build status Pursuit Maintainer: garyb Maintainer: thomashoneyman

EncodeJson and DecodeJson classes and instances, useful combinators for encoding and decoding Json values.

Installation

bower install purescript-argonaut-codecs

Documentation

Module documentation is published on Pursuit.

Example

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"

Contributing

Read the contribution guidelines to get started and see helpful related resources.