json-query 0.2.0.0 → 0.2.1.0
raw patch · 4 files changed
+30/−5 lines, 4 filesdep ~bytestringdep ~json-syntaxdep ~primitive
Dependency ranges changed: bytestring, json-syntax, primitive, primitive-unlifted, scientific-notation
Files
- CHANGELOG.md +5/−0
- json-query.cabal +4/−4
- src/Json/Arrow.hs +1/−1
- src/Json/Parser.hs +20/−0
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for json-query +## 0.2.1.0 -- 2021-07-15++* Allow building with GHC 9.2.3+* Export `unMembers`+ ## 0.2.0.0 -- 2021-09-07 * Add `Monad` implementation for `MemberParser`.
json-query.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: json-query-version: 0.2.0.0+version: 0.2.1.0 synopsis: Kitchen sink for querying JSON description: The library complements json-syntax by making available several@@ -28,13 +28,13 @@ , array-chunks >=0.1.2 && <0.2 , base >=4.12 && <5 , bytebuild >=0.3.5 && <0.4- , bytestring >=0.10 && <0.11+ , bytestring >=0.10 && <0.12 , contiguous >=0.6.1- , json-syntax >=0.2 && <0.3+ , json-syntax >=0.2.2 && <0.3 , primitive >=0.7 && <0.8 , primitive-unlifted >=0.1.3 && <0.2 , profunctors >=5.6- , scientific-notation >=0.1.2 && <0.2+ , scientific-notation >=0.1.5 && <0.2 , text-short >=0.1.3 && <0.2 , transformers >=0.5.6 && <0.6 hs-source-dirs: src
src/Json/Arrow.hs view
@@ -19,7 +19,7 @@ , boolean , null -- ** Object Members- , Members+ , Members(..) , member , memberOpt , foldMembers
src/Json/Parser.hs view
@@ -16,6 +16,7 @@ , run -- * Object Parsing , key+ , keyOptNull , members -- * Arrays , smallArray@@ -28,6 +29,7 @@ , string -- * Trivial Combinators , int+ , int32 , word16 , word64 -- * Failing@@ -43,6 +45,7 @@ import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Except (ExceptT(ExceptT),runExceptT) import Data.Foldable (foldlM)+import Data.Int (Int32) import Data.List (find) import Data.Number.Scientific (Scientific) import Data.Primitive (SmallArray)@@ -145,6 +148,11 @@ Just n -> pure n _ -> fail "expected number in signed machine integer range" +int32 :: Scientific -> Parser Int32+int32 m = case SCI.toInt32 m of+ Just n -> pure n+ _ -> fail "expected number in range [-2^31,2^31-1)"+ word16 :: Scientific -> Parser Word16 word16 m = case SCI.toWord16 m of Just n -> pure n@@ -170,6 +178,18 @@ case find (\Member{key=k} -> k == name) mbrs of Nothing -> Left (Errors.singleton (Error{context=p',message="key not found: " <> name})) Just Member{value} -> runParser (f value) p'++-- | Variant of 'key' that supplies the JSON value @null to the+-- callback if the key is not found. Using this parser combinators implies+-- that there is no distinction between @null@ and an absent value in+-- the encoding scheme.+keyOptNull :: ShortText -> (Value -> Parser a) -> MemberParser a+keyOptNull !name f = MemberParser $ \p mbrs ->+ let !p' = Key name p+ val = case find (\Member{key=k} -> k == name) mbrs of+ Nothing -> Json.Null+ Just Member{value} -> value+ in runParser (f val) p' -- object2 :: -- (a -> b -> c)