Skip to content

Commit

Permalink
Merge pull request #16 from phadej/encode-decode
Browse files Browse the repository at this point in the history
Use aeson's decode to parse LBS.ByteString
  • Loading branch information
phadej committed Jun 9, 2023
2 parents 3463629 + 73ab56f commit 275a46d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.1

* Drop dependency on `attoparsec`. Use `aeson`s `decode` to parse `Value`.

# 1.2.0.1

* Drop direct dependency on `unordered-containers`
Expand Down
4 changes: 1 addition & 3 deletions aeson-optics.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: 1.2.0.1
x-revision: 1
version: 1.2.1
name: aeson-optics
category: Data, JSON, Optics
license: MIT
Expand Down Expand Up @@ -42,7 +41,6 @@ library
default-language: Haskell2010
build-depends:
aeson >=2.0.3.0 && <2.2
, attoparsec >=0.13.1.0 && <0.15
, base >=4.10 && <4.19
, bytestring >=0.10.8.1 && <0.12
, optics-core >=0.4.1 && <0.5
Expand Down
11 changes: 2 additions & 9 deletions src/Data/Aeson/Optics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ module Data.Aeson.Optics
import Prelude hiding (null)

import Data.Aeson
(FromJSON, Result (..), ToJSON, Value (..), encode, fromJSON, toJSON)
import Data.Aeson.Parser (value)
import Data.Attoparsec.ByteString.Lazy (maybeResult, parse)
(FromJSON, Result (..), ToJSON, Value (..), encode, fromJSON, toJSON, decode)
import Data.Scientific (Scientific)
import Data.Text (Text)
import Data.Text.Optics (packed)
Expand Down Expand Up @@ -381,12 +379,7 @@ instance AsJSON Strict.ByteString where
{-# INLINE _JSON #-}

instance AsJSON LBS.ByteString where
_JSON = prism' encode decodeValue
where
decodeValue :: (FromJSON a) => LBS.ByteString -> Maybe a
decodeValue s = maybeResult (parse value s) >>= \x -> case fromJSON x of
Success v -> Just v
_ -> Nothing
_JSON = prism' encode decode
{-# INLINE _JSON #-}

instance AsJSON String where
Expand Down

0 comments on commit 275a46d

Please sign in to comment.