The hjsonpointer package

[ Tags: data, library, mit ] [ Propose Tags ]

[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.2.0.3, 0.2.0.4, 0.3.0.0, 0.3.0.1, 0.3.0.2, 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.1.0.0, 1.1.0.1, 1.1.0.2, 1.1.1, 1.2.0, 1.3.0
Change log changelog.md
Dependencies aeson (>=0.7 && <1.3), base (>=4.6 && <4.11), hashable (==1.2.*), QuickCheck (>=2.8 && <2.11), semigroups (==0.18.*), text (==1.2.*), unordered-containers (==0.2.*), vector (>=0.10 && <0.13) [details]
License MIT
Author Ian Grant Jeffries
Maintainer ian@housejeffries.com
Category Data
Home page https://github.com/seagreen/hjsonpointer
Uploaded Tue Sep 19 01:07:07 UTC 2017 by seagreen
Updated Tue Sep 19 03:11:29 UTC 2017 by seagreen to revision 1
Distributions LTSHaskell:1.2.0, NixOS:1.3.0, Stackage:1.3.0, Tumbleweed:1.1.1
Downloads 2338 total (73 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-09-19 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for hjsonpointer-1.3.0

[back to package description]

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