File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -15,3 +15,31 @@ bower install purescript-argonaut-codecs
1515## Documentation
1616
1717Module documentation is [ published on Pursuit] ( http://pursuit.purescript.org/packages/purescript-argonaut-codecs ) .
18+
19+ ## Example
20+
21+ Using [ purescript-argonaut-core] ( https://github.com/purescript-contrib/purescript-argonaut-core ) we can build a simple ` Json ` object:
22+
23+ ``` purescript
24+ someObject = fromObject (StrMap.fromFoldable [
25+ Tuple "foo" (fromArray [
26+ jsonSingletonObject "bar" (fromString "a"),
27+ jsonSingletonObject "bar" (fromString "b")
28+ ])
29+ ])
30+ ```
31+
32+ The ` decodeJson ` and ` .? ` functions provided in this module make it straightforward to interrogate the ` Json ` object:
33+
34+ ``` purescript
35+ main =
36+ log $ show $ getBars someObject
37+
38+ getBars :: Json -> Either String (Array String)
39+ getBars json = do
40+ obj <- decodeJson json
41+ foo <- obj .? "foo"
42+ for foo \itemJson -> do
43+ itemObj <- decodeJson itemJson
44+ itemObj .? "bar"
45+ ```
You can’t perform that action at this time.
0 commit comments