MIT licensed by Ian Grant Jeffries
Maintained by [email protected]
This version can be pinned in stack with:hjsonpointer-0.3.0.1@sha256:9e039d4213cd21d9b5749ae706e819a2cd7f11cb65296f0981152aa8a04b1751,2277

Module documentation for 0.3.0.1

Summary

JSON Pointer library for Haskell.

Hackage / GitHub / Travis CI

Example

{-# LANGUAGE OverloadedStrings #-}

module Main where

import           Control.Monad      (unless)
import           Data.Aeson
import qualified Data.Aeson.Pointer as P

main :: IO ()
main = do
  -- JSON Pointers must either be empty or start with a /.
  pntr1 <- case P.unescape "/foo/0" of
             Left _     -> error "Failed to construct JSON Pointer."
             Right pntr -> pure pntr

  -- We can also write JSON Pointers in Haskell.
  let pntr2 = P.Pointer [P.Token "/"]
  -- When we do this we don't have to escape / or ~ characters
  -- (as ~1 and ~0 respectively) like we do in an escaped JSON
  -- Pointer string.
  unless (P.unescape "/~1" == Right pntr2) (error "ohno!")

  print (P.resolve pntr1 document)
  print (P.resolve pntr2 document)

  where
    document :: Value
    document = object [ "foo" .= [String "bar", String "baz"]
                      , "/"   .= String "quux"
                      ]

Output:

Right (String "bar")
Right (String "quux")

Changes

0.3

  • Rewrite.

0.2

  • Fix mistake in resolveRefTok.
  • Split errors over two types.
  • Switch the order of pointer and value arguments for functions that take both. The pointer now comes first.

0.1

  • Initial implementation.