packages feed

json-pointer-aeson (empty) → 0.1

raw patch · 4 files changed

+104/−0 lines, 4 filesdep +aesondep +base-preludedep +json-pointersetup-changed

Dependencies added: aeson, base-prelude, json-pointer, unordered-containers, vector

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2016, Sannsyn AS++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ json-pointer-aeson.cabal view
@@ -0,0 +1,48 @@+name:+  json-pointer-aeson+version:+  0.1+synopsis:+  Integration layer for "json-pointer" and "aeson"+homepage:+  https://github.com/sannsyn/json-pointer-aeson +bug-reports:+  https://github.com/sannsyn/json-pointer-aeson/issues +author:+  Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+  Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+  (c) 2016, Sannsyn AS+license:+  MIT+license-file:+  LICENSE+build-type:+  Simple+cabal-version:+  >=1.10+++source-repository head+  type:+    git+  location:+    git://github.com/sannsyn/json-pointer-aeson.git+++library+  hs-source-dirs:+    library+  default-extensions:+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveTraversable, DeriveGeneric, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+  default-language:+    Haskell2010+  exposed-modules:+    JSONPointer.Aeson.Interpreter+  build-depends:+    json-pointer >= 0.1 && < 0.2,+    aeson >= 0.8 && < 0.12,+    unordered-containers >= 0.2 && < 0.3,+    vector >= 0.11 && < 0.12,+    base-prelude < 2
+ library/JSONPointer/Aeson/Interpreter.hs view
@@ -0,0 +1,32 @@+module JSONPointer.Aeson.Interpreter where++import BasePrelude+import qualified JSONPointer.Model+import qualified Data.Aeson as Aeson+import qualified Data.HashMap.Strict as HashMap.Strict+import qualified Data.Vector as Vector+++-- |+-- Converts JSONPointer into an Aeson Value lookup function.+value :: JSONPointer.Model.JSONPointer -> Aeson.Value -> Maybe Aeson.Value+value pointer json =+  appEndo (JSONPointer.Model.run pointer interpreter) $+  Just json+  where+    interpreter index key =+      Endo ((=<<) lookup)+      where+        lookup =+          \case+            Aeson.Object x ->+              HashMap.Strict.lookup key x+            Aeson.Array x ->+              (Vector.!?) x =<< index+            _ ->+              Nothing++nullableValue :: JSONPointer.Model.JSONPointer -> Aeson.Value -> Aeson.Value+nullableValue pointer json =+  fromMaybe Aeson.Null $+  value pointer json