aeson-diff-1.1.0.13: Extract and apply patches to JSON documents.

Safe Haskell | None
Language | Haskell2010

Data.Aeson.Pointer

Contents

- Representing pointers
- Using pointers

Description

Synopsis

- newtype Pointer = Pointer {
  - pointerPath :: Path
  }
- data Key
  - = OKey Key
  - | AKey Int
- type Path = [Key]
- formatPointer :: Pointer -> Text
- parsePointer :: Text -> Parser Pointer
- get :: Pointer -> Value -> Result Value
- pointerFailure :: Pointer -> Value -> Result a

# Documentation

newtype Pointer Source #

Pointer to a location in a JSON document.

Defined in RFC 6901 http://tools.ietf.org/html/rfc6901

Constructors

Pointer |

Fields

- pointerPath :: Path

#### Instances

Instances details

FromJSON Pointer Source # |
Instance details Defined in Data.Aeson.Pointer Methods parseJSON :: Value -> Parser Pointer Source # parseJSONList :: Value -> Parser [Pointer] Source # omittedField :: Maybe Pointer Source #
ToJSON Pointer Source # |
Instance details Defined in Data.Aeson.Pointer Methods toJSON :: Pointer -> Value Source # toEncoding :: Pointer -> Encoding Source # toJSONList :: [Pointer] -> Value Source # toEncodingList :: [Pointer] -> Encoding Source # omitField :: Pointer -> Bool Source #
Monoid Pointer Source # |
Instance details Defined in Data.Aeson.Pointer Methods mempty :: Pointer Source # mappend :: Pointer -> Pointer -> Pointer Source # mconcat :: [Pointer] -> Pointer Source #
Semigroup Pointer Source # |
Instance details Defined in Data.Aeson.Pointer Methods (<>) :: Pointer -> Pointer -> Pointer Source # sconcat :: NonEmpty Pointer -> Pointer Source # stimes :: Integral b => b -> Pointer -> Pointer Source #
Generic Pointer Source # |

Instance details

Defined in Data.Aeson.Pointer

Associated Types

type Rep Pointer |
Instance details Defined in Data.Aeson.Pointer type Rep Pointer = D1 ('MetaData "Pointer" "Data.Aeson.Pointer" "aeson-diff-1.1.0.13-RSEUjrZ5DXI4WojbDRtMt" 'True) (C1 ('MetaCons "Pointer" 'PrefixI 'True) (S1 ('MetaSel ('Just "pointerPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Path)))

Methods

from :: Pointer -> Rep Pointer x Source #

to :: Rep Pointer x -> Pointer Source #

Show Pointer Source # |
Instance details Defined in Data.Aeson.Pointer Methods showsPrec :: Int -> Pointer -> ShowS Source # show :: Pointer -> String Source # showList :: [Pointer] -> ShowS Source #
Eq Pointer Source # |
Instance details Defined in Data.Aeson.Pointer Methods (==) :: Pointer -> Pointer -> Bool Source # (/=) :: Pointer -> Pointer -> Bool Source #
Ord Pointer Source # |
Instance details Defined in Data.Aeson.Pointer Methods compare :: Pointer -> Pointer -> Ordering Source # (<) :: Pointer -> Pointer -> Bool Source # (<=) :: Pointer -> Pointer -> Bool Source # (>) :: Pointer -> Pointer -> Bool Source # (>=) :: Pointer -> Pointer -> Bool Source # max :: Pointer -> Pointer -> Pointer Source # min :: Pointer -> Pointer -> Pointer Source #
type Rep Pointer Source # |
Instance details Defined in Data.Aeson.Pointer type Rep Pointer = D1 ('MetaData "Pointer" "Data.Aeson.Pointer" "aeson-diff-1.1.0.13-RSEUjrZ5DXI4WojbDRtMt" 'True) (C1 ('MetaCons "Pointer" 'PrefixI 'True) (S1 ('MetaSel ('Just "pointerPath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Path)))

data Key Source #

Path components to traverse a single layer of a JSON document.

Constructors

OKey Key | Traverse a `Value` with an `Object` constructor.
AKey Int | Traverse a `Value` with an `Array` constructor.

#### Instances

Instances details

FromJSON Key Source # |
Instance details Defined in Data.Aeson.Pointer Methods parseJSON :: Value -> Parser Key Source # parseJSONList :: Value -> Parser [Key] Source # omittedField :: Maybe Key Source #
ToJSON Key Source # |
Instance details Defined in Data.Aeson.Pointer Methods toJSON :: Key -> Value Source # toEncoding :: Key -> Encoding Source # toJSONList :: [Key] -> Value Source # toEncodingList :: [Key] -> Encoding Source # omitField :: Key -> Bool Source #
Generic Key Source # |

Instance details

Defined in Data.Aeson.Pointer

Associated Types

type Rep Key |

Instance details

Defined in Data.Aeson.Pointer

type Rep Key = D1 ('MetaData "Key" "Data.Aeson.Pointer" "aeson-diff-1.1.0.13-RSEUjrZ5DXI4WojbDRtMt" 'False) (C1 ('MetaCons "OKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Key)) :+: C1 ('MetaCons "AKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

Methods

from :: Key -> Rep Key x Source #

to :: Rep Key x -> Key Source #

Show Key Source # |
Instance details Defined in Data.Aeson.Pointer Methods showsPrec :: Int -> Key -> ShowS Source # show :: Key -> String Source # showList :: [Key] -> ShowS Source #
Eq Key Source # |
Instance details Defined in Data.Aeson.Pointer Methods (==) :: Key -> Key -> Bool Source # (/=) :: Key -> Key -> Bool Source #
Ord Key Source # |
Instance details Defined in Data.Aeson.Pointer Methods compare :: Key -> Key -> Ordering Source # (<) :: Key -> Key -> Bool Source # (<=) :: Key -> Key -> Bool Source # (>) :: Key -> Key -> Bool Source # (>=) :: Key -> Key -> Bool Source # max :: Key -> Key -> Key Source # min :: Key -> Key -> Key Source #
type Rep Key Source # |

Instance details

Defined in Data.Aeson.Pointer

type Rep Key = D1 ('MetaData "Key" "Data.Aeson.Pointer" "aeson-diff-1.1.0.13-RSEUjrZ5DXI4WojbDRtMt" 'False) (C1 ('MetaCons "OKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Key)) :+: C1 ('MetaCons "AKey" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

type Path = [Key] Source #

A sequence of `Key`s forms a path through a JSON document.

# Representing pointers

formatPointer :: Pointer -> Text Source #

Format a `Pointer` as described in RFC 6901.

    >>> formatPointer (Pointer [])
    ""
    >>> formatPointer (Pointer [OKey ""])
    "/"
    >>> formatPointer (Pointer [OKey " "])
    "/ "
    >>> formatPointer (Pointer [OKey "foo"])
    "/foo"
    >>> formatPointer (Pointer [OKey "foo", AKey 0])
    "/foo/0"
    >>> formatPointer (Pointer [OKey "a/b"])
    "/a~1b"
    >>> formatPointer (Pointer [OKey "c%d"])
    "/c%d"
    >>> formatPointer (Pointer [OKey "e^f"])
    "/e^f"
    >>> formatPointer (Pointer [OKey "g|h"])
    "/g|h"
    >>> formatPointer (Pointer [OKey "i\\j"])
    "/i\\j"
    >>> formatPointer (Pointer [OKey "k\"l"])
    "/k\"l"
    >>> formatPointer (Pointer [OKey "m~n"])
    "/m~0n"

parsePointer :: Text -> Parser Pointer Source #

Parse a `Pointer` as described in RFC 6901.

# Using pointers

get :: Pointer -> Value -> Result Value Source #

Follow a `Pointer` through a JSON document as described in RFC 6901.

pointerFailure :: Pointer -> Value -> Result a Source #

Report an error while following a pointer.