aeson-jsonpath: Parse and run JSONPath queries on Aeson documents

[ json, library, mit, text, web ] [ Propose Tags ] [ Report a vulnerability ]

RFC 9535 compliant JSONPath parsing and querying package. JSONPath is similar to XPath for querying XML documents.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.0.1, 0.3.0.2
Change log CHANGELOG.md
Dependencies aeson (>=2.0.3 && <2.3), base (>=4.9 && <4.23), parsec (>=3.1.11 && <3.2), scientific (>=0.3.4 && <0.4), template-haskell (>=2.12 && <2.25), text (>=1.2.2 && <2.2), vector (>=0.11 && <0.14) [details]
Tested with ghc ==9.4.8, ghc ==9.6.6, ghc ==9.8.4, ghc ==9.10.1
License MIT
Author Taimoor Zaeem
Maintainer Taimoor Zaeem <mtaimoorzaeem@gmail.com>
Uploaded by taimoorzaeem at 2025-02-19T11:21:07Z
Revised Revision 1 made by taimoorzaeem at 2026-01-07T15:56:04Z
Category JSON, Text, Web
Home page https://github.com/taimoorzaeem/aeson-jsonpath
Bug tracker https://github.com/taimoorzaeem/aeson-jsonpath/issues
Source repo head: git clone https://github.com/taimoorzaeem/aeson-jsonpath
Distributions LTSHaskell:0.3.0.2, NixOS:0.3.0.2, Stackage:0.3.0.2
Downloads 202 total (9 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for aeson-jsonpath-0.3.0.2

[back to package description]

aeson-jsonpath

Build hackage-docs Donate Compliance

Run RFC 9535 compliant JSONPath queries on Data.Aeson.

Roadmap

  • Selectors
    • Name Selector
    • Index Selector
    • Slice Selector
    • Wildcard Selector
    • Filter Selector
  • Segments
    • Child Segment
    • Descendant Segment
  • Normalized Paths
  • Function Extensions

I have decided not to implement Function Extension yet. Please open an issue or discussion if you'd like to see them implemented.

Quick Start

{-# LANGUAGE QuasiQuotes #-}
import Data.Aeson           (Value (..))
import Data.Aeson.QQ.Simple (aesonQQ)
import Data.Aeson.JSONPath  (query, queryLocated, jsonPath)

track = [aesonQQ| { "artist": "Duster", "title": "Earth Moon Transit" } |]

ghci> query "$.artist" track -- child member shorthand
Right [String "Duster"]

ghci> queryLocated "$.*" track -- child wildcard segment
Right [
  ("$['artist']", String "Duster"),
  ("$['title']", String "Earth Moon Transit")
]

More Examples

{-# LANGUAGE QuasiQuotes #-}
import Data.Aeson           (Value (..))
import Data.Aeson.QQ.Simple (aesonQQ)
import Data.Aeson.JSONPath  (query, queryLocated, jsonPath)

json = [aesonQQ| {
  "shop": {
    "movies": [
      {
        "title": "Mandy",
        "director": "Panos Cosmatos",
        "year": 2018
      },
      {
        "title": "Laurence Anyways",
        "director": "Xavier Dolan",
        "year": 2012
      }
    ]
  }
}|]

Child Segment

ghci> query "$.shop.movies[0].title" json
Right [String "Mandy"]

ghci> query "$.shop.movies[0].*" json
Right [
  String "Mandy",
  String "Panos Cosmatos",
  Number 2018.0
]

ghci> query "$['shop']['new-movies']" json
Right []

Descendant Segment

-- get all values with key "director", recursively
ghci> query "$..director" json
Right [
  String "Panos Cosmatos",
  String "Xavier Dolan"
]

Slice Selector

ghci> query "$[2:5]" [aesonQQ| [1,2,3,4,5,6] |]
Right [
  Number 3.0,
  Number 4.0,
  Number 5.0
]

Filter Selector

ghci> query "$.shop.movies[?@.year < 2015]" json
Right [
  Object (fromList [
    ("director",String "Xavier Dolan"),
    ("title",String "Laurence Anyways"),
    ("year",Number 2012.0)
  ])
]

ghci> queryLocated "$.shop.movies[?@.director == 'Panos Cosmatos']" json
Right [
  (
    "$['shop']['movies'][0]",
    Object (fromList [
      ("director",String "Panos Cosmatos"),
      ("title",String "Mandy"),
      ("year",Number 2018.0)
    ])
  )
]

QuasiQuoter

The functions queryQQ and queryLocatedQQ can be used with the jsonPath quasi quoter.

queryQQ [jsonPath|$.shop.movies|] json -- compiles successfully

queryQQ [jsonPath|$.shop$$movies|] json -- compilation error, doesn't parse

Testing

It is tested using 10000+ lines test suite given by jsonpath-compliance-test-suite 🚀.

Note: All tests pass except tests related to function extensions which we have not implemented yet.

Development

Please report any bugs you encounter by opening an issue.