- type Jsons = [Json]
- type JFilter = Json -> Jsons
- emptyObj :: Json
- (-->) :: String -> Json -> Json
- (<>) :: Json -> Json -> Json
- (<.>) :: Json -> Json -> Json
- merges :: [Json] -> Json
- mergesRec :: [Json] -> Json
- isObj :: JFilter
- isArr :: JFilter
- isStr :: JFilter
- isStrBy :: (String -> Bool) -> JFilter
- isNum :: JFilter
- isNumBy :: Fractional a => (a -> Bool) -> JFilter
- isBool :: JFilter
- isNull :: JFilter
- isPrimitive :: JFilter
- getFromKeys :: [String] -> JFilter
- getFromObj :: JFilter
- getFromArr :: JFilter
- getFromIndex :: Int -> JFilter
- getFromIndexes :: [Int] -> JFilter
- getChildern :: JFilter
- getFromKey :: String -> JFilter
- (>>>) :: JFilter -> JFilter -> JFilter
- (<+>) :: JFilter -> JFilter -> JFilter
- orElse :: JFilter -> JFilter -> JFilter
- when :: JFilter -> JFilter -> JFilter
- guards :: JFilter -> JFilter -> JFilter
- deepObj :: JFilter -> JFilter
- deepArr :: JFilter -> JFilter
- deep :: JFilter -> JFilter
Types
Building
mergesRec :: [Json] -> JsonSource
recursive merge lists JSON Objects
Example:
j1 = jParse "{\"Europa\": {\"Ukraine\": [\"Kiyv\", \"Gitomir\", \"Lviv\"]}}" j2 = jParse "{\"Asia\": {\"Japan\": [\"Tokyo\"]}}" j3 = jParse "{\"Europa\": {\"UnitedKingdom\": [\"London\", \"Glasgow\"]}}" j4 = jParse "{\"Europa\": {\"Germany\": [\"Berlin\", \"Bonn\"]}}" j5 = jParse "{\"Africa\": {}}" j6 = jParse"{\"America\": {\"USA\": [], \"Canada\": [\"Toronto\"]}}" j7 = jParse "{\"Australia\": [\"Melburn\", \"Adelaida\"]}" merg = mergsRec [j1, j2, j3, j4, j5, j6, j7] ex0 = pputJson merg
Result:
{ "Africa": { }, "America": { "Canada": ["Toronto"], "USA": [] }, "Asia": { "Japan": ["Tokyo"] }, "Australia": ["Melburn", "Adelaida"], "Europa": { "Germany": ["Berlin", "Bonn"], "Ukraine": ["Kiyv", "Gitomir", "Lviv"], "UnitedKingdom": ["London", "Glasgow"] } }
Filtering
isNumBy :: Fractional a => (a -> Bool) -> JFilterSource
Predicative filter JSON numbers.
Filter primitive types.
getFromKeys :: [String] -> JFilterSource
Get elements from object with keys.
Example:
query1 = getFromKeys ["Europa", "America", "Africa"] json1 = query1 merg ex1 = pputJsons json1
Result:
{ "Germany": ["Berlin", "Bonn"], "Ukraine": ["Kiyv", "Gitomir", "Lviv"], "UnitedKingdom": ["London", "Glasgow"] } { "Canada": ["Toronto"], "USA": [] } { }
Get all elements from object.
Get all elements from array.
getFromIndex :: Int -> JFilterSource
Get element from array with index.
getFromIndexes :: [Int] -> JFilterSource
Get elements from array with indexes.
Get all elements from object and array.
getFromKey :: String -> JFilterSource
Get elements from object with key.
Filter Combinators
(>>>) :: JFilter -> JFilter -> JFilterSource
(f >>> g)
- Apply filter f, later filter g .
Example:
query2 = query1 >>> getFromObj json2 = query2 merg ex2 = pputJsons json2
Result:
["Berlin", "Bonn"] ["Kiyv", "Gitomir", "Lviv"] ["London", "Glasgow"] ["Toronto"] []
guards :: JFilter -> JFilter -> JFilterSource
(f
- If guards
g )f
returned null then null
else apply g
.
deep :: JFilter -> JFilterSource
Tree traversal filter for objects and arrays.
Example:
-- Qwery: All city Europa, America, Australia and Africa -- q31, q32, q33 is equal q31 = getFromKeys ["Europa", "America", "Africa", "Australia"] >>> (getFromArr `orElse` getFromObj) >>> (isStr `orElse` getFromArr) q32 = getFromKeys ["Europa", "America", "Africa", "Australia"] >>> (getFromObj `when` isObj) >>> getFromArr q33 = getFromKeys ["Europa", "America", "Africa", "Australia"] >>> deep getFromArr
See also: http://www.haskell.org/haskellwiki/HXT#The_concept_of_filters