packages feed

aeson-picker 0.1.0.1 → 0.1.0.2

raw patch · 2 files changed

+33/−36 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

aeson-picker.cabal view
@@ -1,5 +1,6 @@ name:           aeson-picker-version:        0.1.0.1+version:        0.1.0.2+synopsis:       Tiny library to get fields from JSON format description:    Tiny library to get fields from JSON format homepage:       https://github.com/ozzzzz/aeson-picker#readme bug-reports:    https://github.com/ozzzzz/aeson-picker/issues
src/Data/Aeson/Picker.hs view
@@ -11,46 +11,42 @@ import           Data.Maybe      (fromMaybe) import           Data.Text       (Text) -{- |-From given JSON and selectors returns typed field. If input JSON is not valid or selected field is not found then error is thrown.-If you need more safe way use '(|-?)' instead. Examples:---- >>> "5" |-- [] :: Int--- 5--- >>> "5" |-- [] :: Float--- 5.0--- >>> "5" |-- [] :: String--- *** Exception: Data.Aeson.Picker: could not pick field with path: []+-- | From given JSON and selectors returns typed field. If input JSON is not valid or selected field is not found then error is thrown.+-- If you need more safe way use '(|-?)' instead. Examples: ----- >>> :set -XOverloadedStrings--- >>> "{\"a\": 5}" |-- ["a"] :: Int--- 5--- >>> "{\"a\": 5}" |-- ["b"] :: Int--- *** Exception: Data.Aeson.Picker: could not pick field with path: ["b"]--- >>> "{\"outer\": {\"inner\": [1,2,3]}}" |-- ["outer", "inner"] :: [Int]--- [1,2,3]--- >>> {\"outer\": {\"inner\": [1,2,3]}}" |-- ["outer", "inner"] :: [Double]--- [1.0,2.0,3.0]--- >>> "{a: 5}" |-- ["a"] :: Int--- *** Exception: Data.Aeson.Picker: input json is not valid--}+-- > ghci> "5" |-- [] :: Int+-- > 5+-- > ghci> "5" |-- [] :: Float+-- > 5.0+-- > ghci>"5" |-- [] :: String+-- > *** Exception: Data.Aeson.Picker: could not pick field with path: []+-- >+-- > ghci> :set -XOverloadedStrings+-- > ghci> "{\"a\": 5}" |-- ["a"] :: Int+-- > 5+-- > ghci> "{\"a\": 5}" |-- ["b"] :: Int+-- > *** Exception: Data.Aeson.Picker: could not pick field with path: ["b"]+-- > ghci> "{\"outer\": {\"inner\": [1,2,3]}}" |-- ["outer", "inner"] :: [Int]+-- > [1,2,3]+-- > ghci> {\"outer\": {\"inner\": [1,2,3]}}" |-- ["outer", "inner"] :: [Double]+-- > [1.0,2.0,3.0]+-- > ghci> "{a: 5}" |-- ["a"] :: Int+-- > *** Exception: Data.Aeson.Picker: input json is not valid infix 5 |-- (|--) :: (AsValue t, FromJSON a) => t -> [Text] -> a json |-- selectors = fromMaybe (error $ "Data.Aeson.Picker: could not pick field with path: " ++ show selectors) $ json |-? selectors -{- |-From given JSON and selectors returns typed field inside 'Maybe'. If input JSON is not valid then error is thrown.-Examples:---- >>> "5" |-? [] :: Maybe Int--- Just 5--- >>> "5" |-? [] :: Maybe String--- Nothing--- >>> "{\"a\": 5}" |-? ["a"] :: Maybe Int--- Just 5--- >>> "{a: 5}" |-? ["a"] :: Maybe Int--- *** Exception: Data.Aeson.Picker: input json is not valid--}+-- | From given JSON and selectors returns typed field inside 'Maybe'. If input JSON is not valid then error is thrown.+-- Examples:+--+-- > ghci> "5" |-? [] :: Maybe Int+-- > Just 5+-- > ghci> "5" |-? [] :: Maybe String+-- > Nothing+-- > ghci> "{\"a\": 5}" |-? ["a"] :: Maybe Int+-- > Just 5+-- > ghci> "{a: 5}" |-? ["a"] :: Maybe Int+-- > *** Exception: Data.Aeson.Picker: input json is not valid infix 5 |-? (|-?) :: (AsValue t, FromJSON a) => t -> [Text] -> Maybe a json |-? selectors = let validJSON = checkValidity json