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

Safe Haskell | None
Language | Haskell2010

Data.Aeson.Diff

Contents

- Patches
- Functions

Description

This module implements data types and operations to represent the differences between JSON documents (i.e. a patch), to compare JSON documents and extract such a patch, and to apply such a patch to a JSON document.

Synopsis

- newtype Patch = Patch [Operation]
- data Pointer
- data Key
  - = OKey Key
  - | AKey Int
- data Operation
  - = Add {
    - changePointer :: Pointer
    - changeValue :: Value
    }
  - | Cpy Pointer Pointer
  - | Mov Pointer Pointer
  - | Rem {
    - changePointer :: Pointer
    }
  - | Rep {
    - changePointer :: Pointer
    - changeValue :: Value
    }
  - | Tst {
    - changePointer :: Pointer
    - changeValue :: Value
    }
- newtype Config = Config {
  - configTstBeforeRem :: Bool
  }
- diff :: Value -> Value -> Patch
- diff' :: Config -> Value -> Value -> Patch
- patch :: Patch -> Value -> Result Value
- applyOperation :: Operation -> Value -> Result Value

# Patches

newtype Patch Source #

Describes the changes between two JSON documents.

Constructors

Patch [Operation] |

#### Instances

Instances details

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

Instance details

Defined in Data.Aeson.Patch

Associated Types

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

Methods

from :: Patch -> Rep Patch x Source #

to :: Rep Patch x -> Patch Source #

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

data Pointer Source #

Pointer to a location in a JSON document.

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

#### 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)))

data Operation Source #

An `Operation` describes the operations which can appear as part of a JSON Patch.

See RFC 6902 Section 4 http://tools.ietf.org/html/rfc6902#section-4.

Constructors

Add | http://tools.ietf.org/html/rfc6902#section-4.1

Fields

- changePointer :: Pointer
- changeValue :: Value

Cpy Pointer Pointer | http://tools.ietf.org/html/rfc6902#section-4.5
Mov Pointer Pointer | http://tools.ietf.org/html/rfc6902#section-4.4
Rem | http://tools.ietf.org/html/rfc6902#section-4.2

Fields

- changePointer :: Pointer

Rep | http://tools.ietf.org/html/rfc6902#section-4.3

Fields

- changePointer :: Pointer
- changeValue :: Value

Tst | http://tools.ietf.org/html/rfc6902#section-4.6

Fields

- changePointer :: Pointer
- changeValue :: Value

#### Instances

Instances details

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

Instance details

Defined in Data.Aeson.Patch

Associated Types

type Rep Operation |

Instance details

Defined in Data.Aeson.Patch

type Rep Operation = D1 ('MetaData "Operation" "Data.Aeson.Patch" "aeson-diff-1.1.0.13-RSEUjrZ5DXI4WojbDRtMt" 'False) ((C1 ('MetaCons "Add" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "changeValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)) :+: (C1 ('MetaCons "Cpy" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "fromPointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer)) :+: C1 ('MetaCons "Mov" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "fromPointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer)))) :+: (C1 ('MetaCons "Rem" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer)) :+: (C1 ('MetaCons "Rep" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "changeValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)) :+: C1 ('MetaCons "Tst" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "changeValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)))))

Methods

from :: Operation -> Rep Operation x Source #

to :: Rep Operation x -> Operation Source #

Show Operation Source # |
Instance details Defined in Data.Aeson.Patch Methods showsPrec :: Int -> Operation -> ShowS Source # show :: Operation -> String Source # showList :: [Operation] -> ShowS Source #
Eq Operation Source # |
Instance details Defined in Data.Aeson.Patch Methods (==) :: Operation -> Operation -> Bool Source # (/=) :: Operation -> Operation -> Bool Source #
type Rep Operation Source # |

Instance details

Defined in Data.Aeson.Patch

type Rep Operation = D1 ('MetaData "Operation" "Data.Aeson.Patch" "aeson-diff-1.1.0.13-RSEUjrZ5DXI4WojbDRtMt" 'False) ((C1 ('MetaCons "Add" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "changeValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)) :+: (C1 ('MetaCons "Cpy" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "fromPointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer)) :+: C1 ('MetaCons "Mov" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "fromPointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer)))) :+: (C1 ('MetaCons "Rem" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer)) :+: (C1 ('MetaCons "Rep" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "changeValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)) :+: C1 ('MetaCons "Tst" 'PrefixI 'True) (S1 ('MetaSel ('Just "changePointer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pointer) :*: S1 ('MetaSel ('Just "changeValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)))))

newtype Config Source #

Configuration for the diff algorithm.

Constructors

Config |

Fields

- configTstBeforeRem :: Bool

# Functions

diff :: Value -> Value -> Patch Source #

Compare two JSON documents and generate a patch describing the differences.

Uses the `defaultConfig`.

diff' :: Config -> Value -> Value -> Patch Source #

Compare two JSON documents and generate a patch describing the differences.

patch :: Patch -> Value -> Result Value Source #

Apply a patch to a JSON document.

applyOperation :: Operation -> Value -> Result Value Source #

Apply an `Operation` to a `Value`.