Skip to content

Commit 5f8ebe5

Browse files
Fix minor typos in readme.md
1 parent 699073d commit 5f8ebe5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ userFromJson = decodeJson
4949

5050
In a REPL we can see these functions in action:
5151

52-
```purs
52+
```sh
5353
> user = { name: "Tom", age: Just 25 }
5454
> stringify (encodeJson user)
5555
"{\"name\":\"Tom\",\"age\":25}"
@@ -84,7 +84,7 @@ bower install purescript-argonaut-codecs purescript-validation
8484
8585
Next, import the modules used in this tutorial -- you can also install `argonaut` and only import `Data.Argonaut` if you'd like to cut down on imports:
8686
87-
```
87+
```purs
8888
import Prelude
8989
9090
import Control.Alternative
@@ -125,7 +125,7 @@ encodeJson :: EncodeJson a => a -> Json
125125
126126
> Tip: There is no `Show` instance for `Json`. To print a `Json` value as a valid JSON string, use `stringify` -- it's the same as the [JavaScript `stringify` method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
127127
128-
```purs
128+
```sh
129129
> user = { name: "Tom", age: Just 25, team: Just "Red Team" } :: User
130130
> stringify (encodeJson user)
131131
"{\"name\":\"Tom\",\"age\":25,\"team\":\"Red Team\"}"
@@ -143,7 +143,7 @@ decodeJson :: DecodeJson a => Json -> Either String a
143143
144144
> Tip: To parse a JSON string as a `Json` value, you can use the `jsonParser` function (which can fail). If you are sure you have valid JSON, then consider writing it in an FFI file and foreign importing it as `Json` as described in the [`argonaut-core` documentation](https://github.com/purescript-contrib/purescript-argonaut-core#introducing-json-values).
145145
146-
```purs
146+
```sh
147147
> userJsonString = """{ "name": "Tom", "age": 25, "team": null }"""
148148
> decodedUser = decodeJson =<< jsonParser userJsonString
149149
@@ -155,7 +155,7 @@ Right "{\"name\":\"Tom\",\"age\":25,\"team\":null}"
155155
156156
Decoding can fail if the `Json` doesn't match the shape expected by a `DecodeJson` instance; in that case, an error is returned instead of the decoded value.
157157
158-
```
158+
```sh
159159
> badUserJsonString = """{ "name": "Tom", "age": null }
160160
> (decodeJson =<< jsonParser badUserJsonString) :: Either String User
161161
Left "JSON was missing expected field: team"
@@ -275,7 +275,7 @@ If your type can be represented easily with a `String`, `Number`, `Boolean`, or
275275
However, quite often your data type will require representation as an object. This library provides combinators in `Data.Argonaut.Decode.Combinators` which are useful for decoding objects into PureScript types by looking up keys in the object and decoding them according to their `DecodeJson` instances.
276276
277277
- Use `.:` (`getField`) to decode a field; if the field is missing, this will decode to a `Maybe`
278-
- Use `.=` (`defaultField`) to provide a default value for a field which may not exist. If decoding fails, you'll still get an error; if decoding succeeds with a value of type `Maybe a`, then this default value will handle the `Nothing` case.
278+
- Use `.!=` (`defaultField`) to provide a default value for a field which may not exist. If decoding fails, you'll still get an error; if decoding succeeds with a value of type `Maybe a`, then this default value will handle the `Nothing` case.
279279
280280
Let's use these combinators to decode a `Json` object into our `AppUser` record.
281281
@@ -475,7 +475,7 @@ newtype User = User
475475
derive instance newtypeUser :: Newtype User _
476476
derive newtype instance showUser :: Show User
477477
478-
decodeUser :: Json -> Either (Array String) User
478+
decodeUser :: Json -> Either String User
479479
decodeUser json = do
480480
obj <- decodeJson json
481481
name <- obj .: "name"
@@ -486,7 +486,7 @@ decodeUser json = do
486486
487487
Running this in the REPL with bad input, we only see the first error:
488488
489-
```purs
489+
```sh
490490
> decodeUser =<< jsonParser "{}"
491491
Left "Expected field \"name\""
492492
```
@@ -517,7 +517,7 @@ decodeUser json = do
517517
age <- obj .:| "age"
518518
location <- obj .:| "location"
519519
in { name, age, location }
520-
pure (User user)
520+
pure $ User user
521521
```
522522
523523
This decoder will now print all errors:

0 commit comments

Comments
 (0)