Skip to content

Commit 24429d5

Browse files
committed
fix: word wrap at 80 chars overall
1 parent f03d8e2 commit 24429d5

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

components/json_path.rst

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ You can install the component in your project using Composer:
3030
Usage
3131
-----
3232

33-
To start querying a JSON document, first create a :class:`Symfony\\Component\\JsonPath\\JsonCrawler`
34-
object from a JSON string. The following examples use this sample "bookstore"
35-
JSON data::
33+
To start querying a JSON document, first create a
34+
:class:`Symfony\\Component\\JsonPath\\JsonCrawler`object from a JSON string. The
35+
following examples use this sample "bookstore" JSON data::
3636
3737
use Symfony\Component\JsonPath\JsonCrawler;
3838
@@ -77,8 +77,9 @@ JSON data::
7777
7878
$crawler = new JsonCrawler($json);
7979
80-
Once you have the crawler instance, use its :method:`Symfony\\Component\\JsonPath\\JsonCrawler::find`
81-
method to start querying the data. This method returns an array of matching values.
80+
Once you have the crawler instance, use its
81+
:method:`Symfony\\Component\\JsonPath\\JsonCrawler::find` method to start
82+
querying the data. This method returns an array of matching values.
8283

8384
Querying with Expressions
8485
-------------------------
@@ -97,9 +98,9 @@ of the document is represented by ``$``::
9798

9899
// $titles is ['Sayings of the Century']
99100

100-
Dot notation is the default, but JSONPath provides other syntaxes for cases where
101-
it doesn't work. Use bracket notation (``['...']``) when a key contains spaces
102-
or special characters::
101+
Dot notation is the default, but JSONPath provides other syntaxes for cases
102+
where it doesn't work. Use bracket notation (``['...']``) when a key contains
103+
spaces or special characters::
103104

104105
// this is equivalent to the previous example
105106
$titles = $crawler->find('$["store"]["book"][0]["title"]');
@@ -119,7 +120,12 @@ you to find values without specifying the full path::
119120
// get all authors from anywhere in the document
120121
$authors = $crawler->find('$..author');
121122

122-
// $authors is ['Nigel Rees', 'Evelyn Waugh', 'Herman Melville', 'John Ronald Reuel Tolkien']
123+
// $authors is equals to [
124+
'Nigel Rees',
125+
'Evelyn Waugh',
126+
'Herman Melville',
127+
'John Ronald Reuel Tolkien'
128+
]
123129

124130
Filtering Results
125131
~~~~~~~~~~~~~~~~~
@@ -135,8 +141,9 @@ Building Queries Programmatically
135141

136142
For more dynamic or complex query building, use the fluent API provided
137143
by the :class:`Symfony\\Component\\JsonPath\\JsonPath` class. This lets you
138-
construct a query object step by step. The ``JsonPath`` object can then be passed
139-
to the crawler's :method:`Symfony\\Component\\JsonPath\\JsonCrawler::find` method.
144+
construct a query object step by step. The ``JsonPath`` object can then be
145+
passed to the crawler's
146+
:method:`Symfony\\Component\\JsonPath\\JsonCrawler::find` method.
140147

141148
The main advantage of the programmatic builder is that it automatically handles
142149
escaping of keys and values, preventing syntax errors::
@@ -178,7 +185,8 @@ methods to build your query:
178185
* :method:`Symfony\\Component\\JsonPath\\JsonPath::index`
179186
Adds an array index selector. Index numbers start at ``0``.
180187

181-
* :method:`Symfony\\Component\\JsonPath\\JsonPath::first` / :method:`Symfony\\Component\\JsonPath\\JsonPath::last`
188+
* :method:`Symfony\\Component\\JsonPath\\JsonPath::first` /
189+
:method:`Symfony\\Component\\JsonPath\\JsonPath::last`
182190
Shortcuts for ``index(0)`` and ``index(-1)`` respectively::
183191

184192
// get the last book: '$["store"]["book"][-1]'
@@ -216,8 +224,10 @@ appropriate (e.g., inside a ``filter()`` expression).
216224
Testing with JSON Assertions
217225
----------------------------
218226

219-
The component provides a set of PHPUnit assertions to make testing JSON data more convenient. Use the
220-
:class:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait` in your test class::
227+
The component provides a set of PHPUnit assertions to make testing JSON data
228+
more convenient. Use the
229+
:class:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait`
230+
in your test class::
221231

222232
use PHPUnit\Framework\TestCase;
223233
use Symfony\Component\JsonPath\Test\JsonPathAssertionsTrait;
@@ -237,27 +247,32 @@ The component provides a set of PHPUnit assertions to make testing JSON data mor
237247
The trait provides the following assertion methods:
238248

239249
* :method:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait::assertJsonPathCount`
240-
Asserts that the number of elements found by the JSONPath expression matches an expected count::
250+
Asserts that the number of elements found by the JSONPath expression matches
251+
an expected count::
241252

242253
$json = '{"a": [1, 2, 3]}';
243254
self::assertJsonPathCount(3, '$.a[*]', $json);
244255

245256
* :method:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait::assertJsonPathEquals`
246-
Asserts that the result of a JSONPath expression is equal to an expected value.The comparison uses ``==`` (type coercion) instead of ``===``::
257+
Asserts that the result of a JSONPath expression is equal to an expected
258+
value. The comparison uses ``==`` (type coercion) instead of ``===``::
247259

248260
$json = '{"a": [1, 2, 3]}';
249261

250262
// passes because "1" == 1
251263
self::assertJsonPathEquals(['1'], '$.a[0]', $json);
252264

253265
* :method:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait::assertJsonPathNotEquals`
254-
Asserts that the result of a JSONPath expression is not equal to an expected value.The comparison uses ``!=`` (type coercion) instead of ``!==``::
266+
Asserts that the result of a JSONPath expression is not equal to an expected
267+
value. The comparison uses ``!=`` (type coercion) instead of ``!==``::
255268

256269
$json = '{"a": [1, 2, 3]}';
257270
self::assertJsonPathNotEquals([42], '$.a[0]', $json);
258271

259272
* :method:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait::assertJsonPathSame`
260-
Asserts that the result of a JSONPath expression is identical (``===``) to an expected value. This is a strict comparison and does not perform type coercion::
273+
Asserts that the result of a JSONPath expression is identical (``===``) to an
274+
expected value. This is a strict comparison and does not perform type
275+
coercion::
261276

262277
$json = '{"a": [1, 2, 3]}';
263278

@@ -267,19 +282,22 @@ The trait provides the following assertion methods:
267282
self::assertJsonPathSame([1], '$.a[0]', $json);
268283

269284
* :method:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait::assertJsonPathNotSame`
270-
Asserts that the result of a JSONPath expression is not identical (``!==``) to an expected value::
285+
Asserts that the result of a JSONPath expression is not identical (``!==``) to
286+
an expected value::
271287

272288
$json = '{"a": [1, 2, 3]}';
273289
self::assertJsonPathNotSame(['1'], '$.a[0]', $json);
274290

275291
* :method:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait::assertJsonPathContains`
276-
Asserts that a given value is found within the array of results from the JSONPath expression::
292+
Asserts that a given value is found within the array of results from the
293+
JSONPath expression::
277294

278295
$json = '{"tags": ["php", "symfony", "json"]}';
279296
self::assertJsonPathContains('symfony', '$.tags[*]', $json);
280297

281298
* :method:`Symfony\\Component\\JsonPath\\Test\\JsonPathAssertionsTrait::assertJsonPathNotContains`
282-
Asserts that a given value is NOT found within the array of results from the JSONPath expression::
299+
Asserts that a given value is NOT found within the array of results from the
300+
JSONPath expression::
283301

284302
$json = '{"tags": ["php", "symfony", "json"]}';
285303
self::assertJsonPathNotContains('java', '$.tags[*]', $json);
@@ -290,11 +308,14 @@ Error Handling
290308
The component throws specific exceptions for invalid input or queries:
291309

292310
* :class:`Symfony\\Component\\JsonPath\\Exception\\InvalidArgumentException`:
293-
Thrown if the input to the ``JsonCrawler`` constructor is not a valid JSON string;
311+
Thrown if the input to the ``JsonCrawler`` constructor is not a valid JSON
312+
string;
294313
* :class:`Symfony\\Component\\JsonPath\\Exception\\InvalidJsonStringInputException`:
295-
Thrown during a ``find()`` call if the JSON string is malformed (e.g., syntax error);
314+
Thrown during a ``find()`` call if the JSON string is malformed
315+
(e.g., syntax error);
296316
* :class:`Symfony\\Component\\JsonPath\\Exception\\JsonCrawlerException`:
297-
Thrown for errors within the JsonPath expression itself, such as using an unknown function
317+
Thrown for errors within the JsonPath expression itself, such as using an
318+
unknown function
298319

299320
Example of handling errors::
300321

0 commit comments

Comments
 (0)