Module
Data.Json.Extended.Cursor
- Package
- purescript-ejson
- Repository
- slamdata/purescript-ejson
#renderEJsonCursor Source
renderEJsonCursor :: Cursor -> String
#peel Source
peel :: Cursor -> Maybe (Tuple Cursor Cursor)
Peels off one layer of a cursor, if possible. The resulting tuple contains the current step (made relative), and the remainder of the cursor.
peel (atKey (EJ.string "foo") $ atIndex 0 all) == Just (Tuple (atKey (EJ.string "foo") all) (atIndex 0 all))
peel (atIndex 0 all) == Just (Tuple (atIndex 0 all) all)
peel all == Nothing
#getKey Source
getKey :: EJson -> EJson -> Maybe EJson
Attempts to lookup a key in an EJson Map, returning the associated value if the key exists and the value is a Map.
getKey (EJ.string "foo") (EJ.map' $ EJ.string <$> SM.fromFoldable [Tuple "foo" "bar"]) == Just (EJ.string "bar")
getKey (EJ.string "foo") (EJ.map' $ EJ.string <$> SM.fromFoldable [Tuple "key" "value"]) == Nothing
getKey (EJ.string "foo") (EJ.boolean false) == Nothing
#setKey Source
setKey :: EJson -> EJson -> EJson -> EJson
For a given key, attempts to set a new value for it in an EJson Map. If the value is not a Map, or the key does not already exist, the original value is returned.
let map = EJ.map' $ EJ.string <$> SM.fromFoldable [Tuple "foo" "bar"]
setKey (EJ.string "foo") (EJ.boolean true) map == EJ.map' (SM.fromFoldable [Tuple "foo" (EJ.boolean true)])
setKey (EJ.string "bar") (EJ.boolean true) map == map
setKey (EJ.string "foo") (EJ.boolean true) (EJ.string "not-a-map") == EJ.string "not-a-map"
#getIndex Source
getIndex :: Int -> EJson -> Maybe EJson
Attempts to lookup an index in an EJson Array, returning the associated value if there is an item at that index, and the value is an Array.
getIndex 0 (EJ.array $ EJ.string <$> ["foo"]) == Just (EJ.string "foo")
getIndex 1 (EJ.array $ EJ.string <$> ["foo"]) == Nothing
getIndex 0 (EJ.boolean false) == Nothing
#setIndex Source
setIndex :: Int -> EJson -> EJson -> EJson
For a given index, attempts to set a new value for it in an EJson Array. If the value is not a Array, or the index does not already exist, the original value is returned.
let array = EJ.array $ EJ.string <$> ["foo"]
setIndex 0 (EJ.boolean true) array == EJ.array [EJ.boolean true]
setIndex 1 (EJ.boolean true) array == array
setIndex 0 (EJ.boolean true) (EJ.string "not-an-array") == EJ.string "not-an-array"