| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
JSONPointer
- data ResolutionError
- resolve :: Pointer -> Value -> Either ResolutionError Value
- newtype Pointer = Pointer {
- _unPointer :: [Token]
- newtype Token = Token {}
- escape :: Pointer -> Text
- data FormatError
- unescape :: Text -> Either FormatError Pointer
- newtype Key = Key {}
- newtype Index = Index {}
- unescapeToken :: Text -> Maybe Token
- resolveToken :: Token -> Value -> Either ResolutionError Value
Resolution
data ResolutionError Source #
Instances
Main types and escaping
Constructors
| Pointer | |
Fields
| |
We don't try to distinguish between integer tokens and string tokens since all tokens start as strings, and all tokens can be used to resolve JSON objects.
Since these are unescaped you can write "/" and "~" normally.
(e.g. if you're referencing a key such as "abc/123", go ahead
and write that exactly.
escape :: Pointer -> Text Source #
This escapes "/" (because it's the token separator character).
It also escapes "~" (because it's the escape character).
data FormatError Source #
Constructors
| InvalidFirstChar | JSON Pointers must either be empty or start with a |
| UnescapedTilde |
Instances
unescape :: Text -> Either FormatError Pointer Source #
JSON Pointers must either be empty or start with a /. This means
that if you're turning a URI Fragment into a JSON Pointer you must
drop the initial #.
Note that the unescaping happening here is not the same as URI
decoding. If you are turning a URI fragment into a JSON Pointer you
must URI decode the Text before using it as an argument to this
function. There's an example of how to do this in the tests using
"Network.HTTP.Types.URI.urlDecode" from http-types.
Wrapper Types
A glorified type alias. If you need to do JSON Pointer operations
you're looking for Token instead.
Internals
resolveToken :: Token -> Value -> Either ResolutionError Value Source #
For internal use (by resolve).
Might also be useful for specialized applications that don't want to resolve an entire pointer at once.