Skip to content

Commit 88086c6

Browse files
authored
Add fromJsonString and toJsonString (#109)
1 parent 176a5dd commit 88086c6

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Added `fromJsonString` and `toJsonString` (#109 by @sigma-andex)
1011

1112
Bugfixes:
1213

packages.dhall

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
let upstream =
2-
https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall
2+
https://github.com/purescript/package-sets/releases/download/psc-0.15.2-20220612/packages.dhall
3+
sha256:9876aee1362a5dac10061768c68a7ecc4a59ca9267c3760f7d43ea9d3812ec11
34

45
in upstream

src/Data/Argonaut/Decode.purs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
module Data.Argonaut.Decode
2-
( module Data.Argonaut.Decode.Class
2+
( fromJsonString
3+
, module Data.Argonaut.Decode.Class
34
, module Data.Argonaut.Decode.Combinators
45
, module Data.Argonaut.Decode.Error
56
, module Data.Argonaut.Decode.Parser
67
) where
78

9+
import Prelude
10+
811
import Data.Argonaut.Decode.Class (class DecodeJson, decodeJson)
9-
import Data.Argonaut.Decode.Combinators
10-
( getField
11-
, getFieldOptional
12-
, getFieldOptional'
13-
, defaultField
14-
, (.:)
15-
, (.:!)
16-
, (.:?)
17-
, (.!=)
18-
)
12+
import Data.Argonaut.Decode.Combinators (getField, getFieldOptional, getFieldOptional', defaultField, (.:), (.:!), (.:?), (.!=))
1913
import Data.Argonaut.Decode.Error (JsonDecodeError(..), printJsonDecodeError)
2014
import Data.Argonaut.Decode.Parser (parseJson)
15+
import Data.Either (Either)
16+
17+
-- | Parse and decode a json in one step.
18+
fromJsonString :: forall json. DecodeJson json => String -> Either JsonDecodeError json
19+
fromJsonString = parseJson >=> decodeJson

src/Data/Argonaut/Encode.purs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
module Data.Argonaut.Encode
22
( module Data.Argonaut.Encode.Class
33
, module Data.Argonaut.Encode.Combinators
4+
, toJsonString
45
) where
56

7+
import Prelude
8+
9+
import Data.Argonaut.Core (stringify)
610
import Data.Argonaut.Encode.Class (class EncodeJson, encodeJson)
7-
import Data.Argonaut.Encode.Combinators
8-
( assoc
9-
, assocOptional
10-
, extend
11-
, extendOptional
12-
, (:=)
13-
, (:=?)
14-
, (~>)
15-
, (~>?)
16-
)
11+
import Data.Argonaut.Encode.Combinators (assoc, assocOptional, extend, extendOptional, (:=), (:=?), (~>), (~>?))
12+
13+
-- | Encode and stringify a type in one step.
14+
toJsonString :: forall t. EncodeJson t => t -> String
15+
toJsonString = encodeJson >>> stringify

0 commit comments

Comments
 (0)