Skip to content

Commit 15ebcd8

Browse files
committed
Prepare for release of version 0.1.0
1 parent e2f497d commit 15ebcd8

File tree

3 files changed

+103
-17
lines changed

3 files changed

+103
-17
lines changed

README.md

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,114 @@
11
# RFC 9535 JSONPath: Query Expressions for JSON in Python
22

3-
We follow [RFC 9535](https://datatracker.ietf.org/doc/html/rfc9535) strictly and test against the [JSONPath Compliance Test Suite](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite).
4-
5-
See also [Python JSONPath](https://github.com/jg-rp/python-jsonpath), which also follows RFC 9535, but with additional features and customization options.
3+
<h1 align="center"># RFC 9535 JSONPath: Query Expressions for JSON in Python</h1>
4+
5+
<p align="center">
6+
We follow <a href="https://datatracker.ietf.org/doc/html/rfc9535">RFC 9535</a> strictly and test against the <a href="https://github.com/jsonpath-standard/jsonpath-compliance-test-suite">JSONPath Compliance Test Suite</a>.
7+
</p>
8+
9+
<p align="center">
10+
<a href="https://github.com/jg-rp/python-jsonpath-rfc9535/blob/main/LICENSE.txt">
11+
<img src="https://img.shields.io/pypi/l/jsonpath-rfc9535?style=flat-square" alt="License">
12+
</a>
13+
<a href="https://github.com/jg-rp/python-jsonpath-rfc9535/actions">
14+
<img src="https://img.shields.io/github/actions/workflow/status/jg-rp/python-jsonpath-rfc9535/tests.yaml?branch=main&label=tests&style=flat-square" alt="Tests">
15+
</a>
16+
<br>
17+
<a href="https://pypi.org/project/jsonpath-rfc9535">
18+
<img src="https://img.shields.io/pypi/v/jsonpath-rfc9535.svg?style=flat-square" alt="PyPi - Version">
19+
</a>
20+
<a href="https://pypi.org/project/jsonpath-rfc9535">
21+
<img src="https://img.shields.io/pypi/pyversions/jsonpath-rfc9535.svg?style=flat-square" alt="Python versions">
22+
</a>
23+
</p>
624

725
---
826

927
**Table of Contents**
1028

1129
- [Install](#install)
30+
- [Example](#example)
1231
- [Links](#links)
13-
- [Usage](#usage)
32+
- [Related projects](#related-projects)
33+
- [API](#api)
1434
- [License](#license)
1535

1636
## Install
1737

18-
TODO:
38+
Install Python JSONPath RFC 9535 using [pip](https://pip.pypa.io/en/stable/getting-started/):
39+
40+
```
41+
pip install jsonpath-rfc9535
42+
```
43+
44+
Or [Pipenv](https://pipenv.pypa.io/en/latest/):
45+
46+
```
47+
pipenv install -u jsonpath-rfc9535
48+
```
49+
50+
## Example
51+
52+
```python
53+
import jsonpath_rfc9535 as jsonpath
54+
55+
data = {
56+
"users": [
57+
{"name": "Sue", "score": 100},
58+
{"name": "Sally", "score": 84, "admin": False},
59+
{"name": "John", "score": 86, "admin": True},
60+
{"name": "Jane", "score": 55},
61+
],
62+
"moderator": "John",
63+
}
64+
65+
for node in jsonpath.find("$.users[?@.score > 85]", data):
66+
print(node.value)
67+
68+
# {'name': 'Sue', 'score': 100}
69+
# {'name': 'John', 'score': 86, 'admin': True}
70+
```
71+
72+
Or, reading JSON data from a file:
73+
74+
```python
75+
import json
76+
import jsonpath_rfc9535 as jsonpath
77+
78+
with open("/path/to/some.json", encoding="utf-8") as fd:
79+
data = json.load(fd)
80+
81+
nodes = jsonpath.find("$.some.query", data)
82+
values = nodes.values()
83+
# ...
84+
```
85+
86+
You could read data from a YAML formatted file too. If you have [PyYaml](https://pyyaml.org/wiki/PyYAML) installed:
87+
88+
```python
89+
import jsonpath_rfc9535 as jsonpath
90+
import yaml
91+
92+
with open("some.yaml") as fd:
93+
data = yaml.safe_load(fd)
94+
95+
products = jsonpath.find("$..products.*", data).values()
96+
# ...
97+
```
1998

2099
## Links
21100

22101
- Change log: https://github.com/jg-rp/python-jsonpath-rfc9535/blob/main/CHANGELOG.md
23-
- PyPi: TODO
102+
- PyPi: [TODO](https://pypi.org/project/jsonpath-rfc9535)
24103
- Source code: https://github.com/jg-rp/python-jsonpath-rfc9535
25104
- Issue tracker: https://github.com/jg-rp/python-jsonpath-rfc9535/issues
26105

27-
## Usage
106+
## Related projects
107+
108+
- [Python JSONPath](https://github.com/jg-rp/python-jsonpath) - Another Python package implementing JSONPath, but with additional features and customization options.
109+
- [JSON P3](https://github.com/jg-rp/json-p3) - RFC 9535 implemented in TypeScript.
110+
111+
## API
28112

29113
### find
30114

@@ -40,13 +124,6 @@ Each `JSONPathNode` has:
40124
- a `location` property, which is a tuple of property names and array/list indexes that were required to reach the node's value in the target JSON document.
41125
- a `path()` method, which returns the normalized path to the node in the target JSON document.
42126

43-
The returned list is a subclass of `list` with some helper methods.
44-
45-
- `values()` returns a list of values, one for each node.
46-
- `items()` returns a list of `(normalized path, value)` tuples, one tuple for each node in the list.
47-
48-
**Example:**
49-
50127
```python
51128
import jsonpath_rfc9535 as jsonpath
52129

@@ -67,6 +144,11 @@ for node in jsonpath.find("$.users[?@.score > 85]", value):
67144
# {'name': 'John', 'score': 86, 'admin': True} at '$['users'][1]'
68145
```
69146

147+
`JSONPathNodeList` is a subclass of `list` with some helper methods.
148+
149+
- `values()` returns a list of values, one for each node.
150+
- `items()` returns a list of `(normalized path, value)` tuples.
151+
70152
### find_one
71153

72154
`find_one(query: str, value: JSONValue) -> Optional[JSONPathNode]`

jsonpath_rfc9535/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.1"
1+
__version__ = "0.1.0"

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

55
[project]
6-
name = "python-jsonpath-rfc9535"
6+
name = "jsonpath-rfc9535"
77
dynamic = ["version"]
88
description = 'RFC 9535 - JSONPath: Query Expressions for JSON in Python'
99
readme = "README.md"
@@ -68,7 +68,11 @@ python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
6868
[tool.coverage.run]
6969
branch = true
7070
parallel = true
71-
omit = ["jsonpath/__about__.py", "tests/compliance.py", "tests/consensus.py"]
71+
omit = [
72+
"jsonpath_rfc9535/__about__.py",
73+
"jsonpath_rfc9535/__main__.py",
74+
"jsonpath_rfc9535/utils/nondeterministic_descent.py",
75+
]
7276

7377
[tool.coverage.report]
7478
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]

0 commit comments

Comments
 (0)