Skip to content

Commit 4014919

Browse files
committed
New:Add section of "Usage via CLI" into docs
1 parent cd57416 commit 4014919

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

README.rst

+27
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ Or use the `jsonpath.core <https://jsonpath.readthedocs.io/en/latest/api_core.ht
6666
Contains(Self().Name("category"), Root().Name("targetCategory"))
6767
).find(data) == [{"price": 100, "category": "Comic book"}]
6868
69+
70+
Usage via CLI
71+
~~~~~~~~~~~~~
72+
73+
The faster way to extract by using CLI.
74+
75+
.. code-block:: shell
76+
77+
jp -f example.json "$.goods[contains(@.category, $.targetCategory)]"
78+
79+
Or pass content by pipeline.
80+
81+
.. code-block:: shell
82+
83+
cat example.json | jp "$.goods[contains(@.category, $.targetCategory)]"
84+
85+
The output of the above commands.
86+
87+
.. code-block:: json
88+
89+
[
90+
{
91+
"price": 100,
92+
"category": "Comic book"
93+
}
94+
]
95+
6996
Changelog
7097
<<<<<<<<<
7198

docs/source/quickstarts.rst

+27
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,30 @@ Or use the :py:mod:`jsonpath.core` module to extract it.
4949
assert Root().Name("goods").Predicate(
5050
Contains(Self().Name("category"), Root().Name("targetCategory"))
5151
).find(data) == [{"price": 100, "category": "Comic book"}]
52+
53+
54+
Usage via CLI
55+
~~~~~~~~~~~~~
56+
57+
The faster way to extract by using CLI.
58+
59+
.. code-block:: shell
60+
61+
jp -f example.json "$.goods[contains(@.category, $.targetCategory)]"
62+
63+
Or pass content by pipeline.
64+
65+
.. code-block:: shell
66+
67+
cat example.json | jp "$.goods[contains(@.category, $.targetCategory)]"
68+
69+
The output of the above commands.
70+
71+
.. code-block:: json
72+
73+
[
74+
{
75+
"price": 100,
76+
"category": "Comic book"
77+
}
78+
]

example.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"goods": [
3+
{"price": 100, "category": "Comic book"},
4+
{"price": 200, "category": "magazine"},
5+
{"price": 200, "no category": ""}
6+
],
7+
"targetCategory": "book"
8+
}

0 commit comments

Comments
 (0)