JSON Pointer library for Haskell
Go to file
Ian Jeffries 75ed0d049c
Merge pull request #6 from hvr/patch-1
Tighten bounds of base
2018-10-01 11:38:56 -04:00
src Removed dependency on QuickCheck 2018-08-24 15:29:51 +02:00
test Regenerate .travis.yaml; bump lts. 2018-09-30 14:16:15 -04:00
.travis.yml Regenerate .travis.yaml; bump lts. 2018-09-30 14:16:15 -04:00
changelog.md Regenerate .travis.yaml; bump lts. 2018-09-30 14:16:15 -04:00
Example.hs 1.1.0.0. 2017-01-06 02:10:57 -05:00
hjsonpointer.cabal Tighten bounds of base 2018-09-30 23:59:34 +02:00
MIT-LICENSE.txt 1.0.0.1: Remove HUnit dep. 2016-10-07 13:29:50 -04:00
README.md 1.1.0.0. 2017-01-06 02:10:57 -05:00
Setup.hs Initial version. 2015-02-22 18:53:24 -05:00
shell.nix 1.3.0. Enable GHC 8.2.1. 2017-09-18 19:34:32 -04:00
stack.yaml Regenerate .travis.yaml; bump lts. 2018-09-30 14:16:15 -04:00

Summary

JSON Pointer library for Haskell.

Hackage / GitHub / Travis CI

Example

module Example where

import           Control.Monad (unless)
import           Data.Aeson
import qualified JSONPointer   as JP

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

    -- We can also write JSON Pointers in Haskell.
    let pntr2 = JP.Pointer [JP.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 (JP.unescape "/~1" == Right pntr2) (error "ohno!")

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

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

Output:

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