Skip to main content

JMESPath

JMESPath allows you to declaratively specify how to extract elements from a JSON document.

For example, given this document:

{"foo": {"bar": "baz"}}

The jmespath expression foo.bar will return “baz”.

JMESPath also supports:

Referencing elements in a list. Given the data:

{"foo": {"bar": ["one", "two"]}}

The expression: foo.bar[0] will return “one”. You can also reference all the items in a list using the * syntax:

{"foo": {"bar": [{"name": "one"}, {"name": "two"}]}}

The expression: foo.bar[*].name will return [“one”, “two”]. Negative indexing is also supported (-1 refers to the last element in the list). Given the data above, the expression foo.bar[-1].name will return [“two”].

The * can also be used for hash types:

{"foo": {"bar": {"name": "one"}, "baz": {"name": "two"}}}

The expression: foo.*.name will return [“one”, “two”].

NOTE: jmespath is being actively developed. There are a number of features it does not currently support that may be added in the future.

Grammar

expression : expression '.' expression
           | expression '[' (number|star) ']
           | expression '.' star
           | identifier
star : '*'
identifier : [a-zA-Z_][a-zA-Z0-9']+
number : -?[0-9]+

Testing

In addition to the unit tests for the jmespath modules, there is a tests/compliance directory that contains .json files with test cases. This allows other implementations to verify they are producing the correct output. Each json file is grouped by feature.

Python Library

The included python implementation has two convenience functions that operate on python data structures. You can use search and give it the jmespath expression and the data:

>>> import jmespath
>>> path = jmespath.search('foo.bar', {'foo': {'bar': 'baz'}})
'baz'

Similar to the re module, you can store the compiled expressions and reuse them to perform repeated searches:

>>> import jmespath
>>> path = jmespath.compile('foo.bar')
>>> path.search({'foo': {'bar': 'baz'}})
'baz'
>>> path.search({'foo': {'bar': 'other'}})
'other'

You can also use the jmespath.parser.Parser class directly if you want more control.

Metadata

Release files for jmespath 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jmespath 0.0.1
File Size Uploaded Provenance Actions
jmespath-0.0.1.tar.gz 6.8 kB Without provenance Details for jmespath-0.0.1.tar.gz

Release files / jmespath-0.0.1.tar.gz

Download URL jmespath-0.0.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
00b4b8b6f3028cf61f1d6cc1ce429bf22920247eb50578b47ca18564ec1b5111
BLAKE2b-256 checksum
How to use checksums
c677a557fe7483826488f2d40aa68e21abed7cfc1522775d410008f11eb52bfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for jmespath 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page