JSON Pointer library for Haskell
Go to file
2016-05-26 12:07:39 -04:00
src/Data/Aeson 0.3.0.0 - rewrite. 2016-02-19 16:58:24 -05:00
tests 0.3.0.0 - rewrite. 2016-02-19 16:58:24 -05:00
.travis.yml Enable GHC 8. 2016-05-26 12:05:18 -04:00
changelog.md 0.3.0.0 - rewrite. 2016-02-19 16:58:24 -05:00
Example.hs 0.3.0.0 - rewrite. 2016-02-19 16:58:24 -05:00
hjsonpointer.cabal 0.3.0.1 2016-05-26 12:06:56 -04:00
MIT-LICENSE.txt Initial version. 2015-02-22 18:53:24 -05:00
README.md 0.3.0.0 - rewrite. 2016-02-19 16:58:24 -05:00
Setup.hs Initial version. 2015-02-22 18:53:24 -05:00

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