Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
JsonPath
is a simple class implementing the JSONPath syntax for extracting
data out of a JSON tree.
While the semantics of the JSONPath expressions are heavily borrowed by the XPath specification for XML, the syntax follows the ECMAScript origins of JSON.
Once a JsonPath
instance has been created, it has to compile a JSONPath
expression using [methodjson
.Path.compile] before being able to match it to
a JSON tree; the same JsonPath
instance can be used to match multiple JSON
trees. It it also possible to compile a new JSONPath expression using the
same JsonPath
instance; the previous expression will be discarded only if
the compilation of the new expression is successful.
The simple convenience function [funcjson
.Path.query] can be used for
one-off matching.
Syntax of the JSONPath expressions
A JSONPath expression is composed by path indices and operators.
Each path index can either be a member name or an element index inside
a JSON tree. A JSONPath expression must start with the $
operator; each
path index is separated using either the dot notation or the bracket
notation, e.g.:
``@ // dot notation
Synopsis
- newtype Path = Path (ManagedPtr Path)
- class (GObject o, IsDescendantOf Path o) => IsPath o
- toPath :: (MonadIO m, IsPath o) => o -> m Path
- pathCompile :: (HasCallStack, MonadIO m, IsPath a) => a -> Text -> m ()
- pathMatch :: (HasCallStack, MonadIO m, IsPath a) => a -> Node -> m Node
- pathNew :: (HasCallStack, MonadIO m) => m Path
- pathQuery :: (HasCallStack, MonadIO m) => Text -> Node -> m Node
Exported types
Memory-managed wrapper type.
Instances
Eq Path Source # | |
GObject Path Source # | |
Defined in GI.Json.Objects.Path | |
ManagedPtrNewtype Path Source # | |
Defined in GI.Json.Objects.Path toManagedPtr :: Path -> ManagedPtr Path # | |
TypedObject Path Source # | |
Defined in GI.Json.Objects.Path | |
HasParentTypes Path Source # | |
Defined in GI.Json.Objects.Path | |
IsGValue (Maybe Path) Source # | Convert |
Defined in GI.Json.Objects.Path | |
type ParentTypes Path Source # | |
Defined in GI.Json.Objects.Path |
class (GObject o, IsDescendantOf Path o) => IsPath o Source #
Instances
(GObject o, IsDescendantOf Path o) => IsPath o Source # | |
Defined in GI.Json.Objects.Path |
Methods
Click to display all available methods, including inherited ones
Methods
bindProperty, bindPropertyFull, compile, forceFloating, freezeNotify, getv, isFloating, match, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, unref, watchClosure.
Getters
getData, getProperty, getQdata.
Setters
compile
:: (HasCallStack, MonadIO m, IsPath a) | |
=> a |
|
-> Text |
|
-> m () | (Can throw |
Validates and decomposes the given expression.
A JSONPath expression must be compiled before calling
[methodjson
.Path.match].
Since: 0.14
match
:: (HasCallStack, MonadIO m, IsPath a) | |
=> a |
|
-> Node |
|
-> m Node | Returns: a newly-created node of type
|
Matches the JSON tree pointed by root
using the expression compiled
into the JsonPath
.
The nodes matching the expression will be copied into an array.
Since: 0.14
new
:: (HasCallStack, MonadIO m) | |
=> m Path | Returns: the newly created path |
Creates a new JsonPath
instance.
Once created, the JsonPath
object should be used with
[methodjson
.Path.compile] and [methodjson
.Path.match].
Since: 0.14
query
:: (HasCallStack, MonadIO m) | |
=> Text |
|
-> Node |
|
-> m Node | Returns: a newly-created node of type
|
Queries a JSON tree using a JSONPath expression.
This function is a simple wrapper around [ctorjson
.Path.new],
[methodjson
.Path.compile], and [methodjson
.Path.match]. It implicitly
creates a JsonPath
instance, compiles the given expression and matches
it against the JSON tree pointed by root
.
Since: 0.14