packages feed

aeson-diff 1.1.0.13 → 1.1.0.14

raw patch · 4 files changed

+36/−19 lines, 4 filesdep ~basePVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Data.Aeson.Pointer: toAesonKey :: Key -> Key

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+aeson-diff 1.1.0.14++    * Fix pointer application after json roundtrip+      https://github.com/clintonmead/aeson-diff/pull/13+ aeson-diff 1.1.0.5      * Support GHC-8.4.x in recent Stackage releases.
aeson-diff.cabal view
@@ -1,5 +1,5 @@ name:                aeson-diff-version:             1.1.0.13+version:             1.1.0.14 synopsis:            Extract and apply patches to JSON documents. description:   .@@ -34,7 +34,7 @@   exposed-modules:     Data.Aeson.Diff                      , Data.Aeson.Patch                      , Data.Aeson.Pointer-  build-depends:       base >=4.11.1 && <4.17+  build-depends:       base >=4.11.1 && <5                      , aeson >= 2.0.3                      , bytestring >= 0.10                      , edit-distance-vector@@ -47,7 +47,7 @@   hs-source-dirs:      src   main-is:             diff.hs   other-modules:       Codec-  build-depends:       base+  build-depends:       base <5                      , aeson >= 2.0.3                      , aeson-diff                      , bytestring@@ -59,7 +59,7 @@   hs-source-dirs:      src   main-is:             patch.hs   other-modules:       Codec-  build-depends:       base+  build-depends:       base <5                      , aeson >= 2.0.3                      , aeson-diff                      , bytestring@@ -71,7 +71,7 @@   type:                exitcode-stdio-1.0   hs-source-dirs:      test   main-is:             properties.hs-  build-depends:       base+  build-depends:       base <5                      , QuickCheck                      , aeson >= 2.0.3                      , aeson-diff@@ -83,7 +83,7 @@   type:                exitcode-stdio-1.0   hs-source-dirs:      test   main-is:             examples.hs-  build-depends:       base+  build-depends:       base <5                      , Glob                      , aeson >= 2.0.3                      , aeson-diff@@ -97,7 +97,7 @@   type:                exitcode-stdio-1.0   ghc-options:         -threaded   main-is:             doctests.hs-  build-depends:       base+  build-depends:       base <5                      , doctest >= 0.18.2   other-modules:       Build_doctests   autogen-modules:     Build_doctests
lib/Data/Aeson/Diff.hs view
@@ -34,7 +34,7 @@ import           Data.Vector.Distance       (Params(Params, equivalent, positionOffset, substitute, insert, delete, cost), leastChanges)  import Data.Aeson.Patch                     (Operation(Add, Cpy, Mov, Rem, Rep, Tst), Patch(Patch), changePointer, changeValue, modifyPointer)-import Data.Aeson.Pointer                   (Key(AKey, OKey), Pointer(Pointer), formatPointer, get, pointerFailure, pointerPath)+import Data.Aeson.Pointer                   (Key(AKey, OKey), Pointer(Pointer), formatPointer, get, pointerFailure, pointerPath, toAesonKey)  -- * Configuration @@ -243,10 +243,11 @@             fn Nothing  = cannot "insert" "array" i pointer             fn (Just d) = Just <$> go (Pointer path) v' d         in Array <$> vModify i fn v-    go (Pointer [OKey n]) v' (Object m) =-        return . Object $ HM.insert n v' m-    go (Pointer (OKey n : path)) v' (Object o) =-        let fn :: Maybe Value -> Result (Maybe Value)+    go (Pointer [key]) v' (Object m) =+        return . Object $ HM.insert (toAesonKey key) v' m+    go (Pointer (key : path)) v' (Object o) =+        let n = toAesonKey key+            fn :: Maybe Value -> Result (Maybe Value)             fn Nothing  = cannot "insert" "object" n pointer             fn (Just d) = Just <$> go (Pointer path) v' d         in Object <$> hmModify n fn o@@ -273,13 +274,15 @@             fn Nothing  = cannot "traverse" "array" i from             fn (Just o) = Just <$> go path o         in Array <$> vModify i fn v-    go [OKey n] (Object m) =-        let fn :: Maybe Value -> Result (Maybe Value)+    go [key] (Object m) =+        let n = toAesonKey key+            fn :: Maybe Value -> Result (Maybe Value)             fn Nothing  = cannot "delete" "object" n from             fn (Just _) = return Nothing         in Object <$> hmModify n fn m-    go (OKey n : path) (Object m) =-        let fn :: Maybe Value -> Result (Maybe Value)+    go (key : path) (Object m) =+        let n = toAesonKey key+            fn :: Maybe Value -> Result (Maybe Value)             fn Nothing  = cannot "traverse" "object" n from             fn (Just o) = Just <$> go path o         in Object <$> hmModify n fn m
lib/Data/Aeson/Pointer.hs view
@@ -10,13 +10,14 @@   formatPointer,   parsePointer,   -- * Using pointers+  toAesonKey,   get,   pointerFailure, ) where  import           Data.Aeson (encode) import qualified Data.Aeson.Key (Key)-import           Data.Aeson.Key (fromText, toText)+import           Data.Aeson.Key (fromText, fromString, toText) import qualified Data.Aeson.KeyMap as HM import           Data.Aeson.Types (FromJSON(parseJSON), Parser, Result(Error), ToJSON(toJSON), Value(Array, Object, Number, String), modifyFailure) import qualified Data.ByteString.Lazy.Char8 as BS@@ -35,6 +36,14 @@     | AKey Int                -- ^ Traverse a 'Value' with an 'Array' constructor.   deriving (Eq, Ord, Show, Generic) +-- | Convert a path component to a JSON object key.+toAesonKey :: Key -> Data.Aeson.Key.Key+toAesonKey key = case key of+  OKey x -> x+  -- According to https://datatracker.ietf.org/doc/html/rfc6901#section-4+  -- strings containing numbers are valid to reference in an object.+  AKey x -> fromString $ show x+ instance ToJSON Key where     toJSON (OKey t) = toJSON t     toJSON (AKey a) = Number . fromInteger . toInteger $ a@@ -131,8 +140,8 @@ get (Pointer []) v = return v get (Pointer (AKey i : path)) (Array v) =   maybe (fail "") return (v V.!? i) >>= get (Pointer path)-get (Pointer (OKey n : path)) (Object v) =-  maybe (fail "") return (HM.lookup n v) >>= get (Pointer path)+get (Pointer (key : path)) (Object v) =+  maybe (fail "") return (HM.lookup (toAesonKey key) v) >>= get (Pointer path) get pointer value = pointerFailure pointer value  -- | Report an error while following a pointer.