Skip to content

Commit ad3f520

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

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

components/json_path.rst

Lines changed: 44 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,31 @@ 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 value.
258+
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 coercion::
261275

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

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

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

272287
$json = '{"a": [1, 2, 3]}';
273288
self::assertJsonPathNotSame(['1'], '$.a[0]', $json);
274289

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

278294
$json = '{"tags": ["php", "symfony", "json"]}';
279295
self::assertJsonPathContains('symfony', '$.tags[*]', $json);
280296

281297
* :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::
298+
Asserts that a given value is NOT found within the array of results from the
299+
JSONPath expression::
283300

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

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

299319
Example of handling errors::
300320

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy