gi-json-1.0.2: JSON GObject bindings
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.Json.Objects.Path

Description

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

Exported types

newtype Path Source #

Memory-managed wrapper type.

Constructors

Path (ManagedPtr Path) 

Instances

Instances details
Eq Path Source # 
Instance details

Defined in GI.Json.Objects.Path

Methods

(==) :: Path -> Path -> Bool #

(/=) :: Path -> Path -> Bool #

GObject Path Source # 
Instance details

Defined in GI.Json.Objects.Path

ManagedPtrNewtype Path Source # 
Instance details

Defined in GI.Json.Objects.Path

TypedObject Path Source # 
Instance details

Defined in GI.Json.Objects.Path

Methods

glibType :: IO GType #

HasParentTypes Path Source # 
Instance details

Defined in GI.Json.Objects.Path

IsGValue (Maybe Path) Source #

Convert Path to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.Json.Objects.Path

type ParentTypes Path Source # 
Instance details

Defined in GI.Json.Objects.Path

class (GObject o, IsDescendantOf Path o) => IsPath o Source #

Type class for types which can be safely cast to Path, for instance with toPath.

Instances

Instances details
(GObject o, IsDescendantOf Path o) => IsPath o Source # 
Instance details

Defined in GI.Json.Objects.Path

toPath :: (MonadIO m, IsPath o) => o -> m Path Source #

Cast to Path, for types for which this is known to be safe. For general casts, use castTo.

Methods

compile

pathCompile Source #

Arguments

:: (HasCallStack, MonadIO m, IsPath a) 
=> a

path: a path

-> Text

expression: a JSONPath expression

-> m ()

(Can throw GError)

Validates and decomposes the given expression.

A JSONPath expression must be compiled before calling [methodjson.Path.match].

Since: 0.14

match

pathMatch Source #

Arguments

:: (HasCallStack, MonadIO m, IsPath a) 
=> a

path: a compiled path

-> Node

root: the root node of the JSON data to match

-> m Node

Returns: a newly-created node of type JSON_NODE_ARRAY containing the array of matching nodes

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

pathNew Source #

Arguments

:: (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

pathQuery Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

expression: a JSONPath expression

-> Node

root: the root of a JSON tree

-> m Node

Returns: a newly-created node of type JSON_NODE_ARRAY containing the array of matching nodes (Can throw GError)

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