|
402 | 402 | </label> |
403 | 403 | <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> |
404 | 404 |
|
| 405 | + <li class="md-nav__item"> |
| 406 | + <a href="#count" class="md-nav__link"> |
| 407 | + count() |
| 408 | + </a> |
| 409 | + |
| 410 | +</li> |
| 411 | + |
405 | 412 | <li class="md-nav__item"> |
406 | 413 | <a href="#length" class="md-nav__link"> |
407 | 414 | length() |
408 | 415 | </a> |
409 | 416 |
|
| 417 | +</li> |
| 418 | + |
| 419 | + <li class="md-nav__item"> |
| 420 | + <a href="#match" class="md-nav__link"> |
| 421 | + match() |
| 422 | + </a> |
| 423 | + |
| 424 | +</li> |
| 425 | + |
| 426 | + <li class="md-nav__item"> |
| 427 | + <a href="#search" class="md-nav__link"> |
| 428 | + search() |
| 429 | + </a> |
| 430 | + |
| 431 | +</li> |
| 432 | + |
| 433 | + <li class="md-nav__item"> |
| 434 | + <a href="#value" class="md-nav__link"> |
| 435 | + value() |
| 436 | + </a> |
| 437 | + |
410 | 438 | </li> |
411 | 439 |
|
412 | 440 | </ul> |
|
543 | 571 | </label> |
544 | 572 | <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> |
545 | 573 |
|
| 574 | + <li class="md-nav__item"> |
| 575 | + <a href="#count" class="md-nav__link"> |
| 576 | + count() |
| 577 | + </a> |
| 578 | + |
| 579 | +</li> |
| 580 | + |
546 | 581 | <li class="md-nav__item"> |
547 | 582 | <a href="#length" class="md-nav__link"> |
548 | 583 | length() |
549 | 584 | </a> |
550 | 585 |
|
| 586 | +</li> |
| 587 | + |
| 588 | + <li class="md-nav__item"> |
| 589 | + <a href="#match" class="md-nav__link"> |
| 590 | + match() |
| 591 | + </a> |
| 592 | + |
| 593 | +</li> |
| 594 | + |
| 595 | + <li class="md-nav__item"> |
| 596 | + <a href="#search" class="md-nav__link"> |
| 597 | + search() |
| 598 | + </a> |
| 599 | + |
| 600 | +</li> |
| 601 | + |
| 602 | + <li class="md-nav__item"> |
| 603 | + <a href="#value" class="md-nav__link"> |
| 604 | + value() |
| 605 | + </a> |
| 606 | + |
551 | 607 | </li> |
552 | 608 |
|
553 | 609 | </ul> |
|
566 | 622 |
|
567 | 623 |
|
568 | 624 | <h1 id="filter-functions">Filter Functions</h1> |
569 | | -<p>TODO:</p> |
| 625 | +<p>A filter function is a named function that can be called as part of a <a href="../syntax/#filters-expression">filter selector</a> expression. Here we describe the standard, built-in filters. You can <a href="../advanced/">define your own function extensions</a> too.</p> |
| 626 | +<h2 id="count"><code>count()</code></h2> |
| 627 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a>count(obj: object) -> Optional[int] |
| 628 | +</span></code></pre></div> |
| 629 | +<p>Return the number of items in <em>obj</em>. If the object does not respond to Python's <code>len()</code> function, <code>None</code> is returned.</p> |
| 630 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a>$.categories[?count(@.products.*) >= 2] |
| 631 | +</span></code></pre></div> |
| 632 | +<div class="admonition warning"> |
| 633 | +<p class="admonition-title">Warning</p> |
| 634 | +<p>As of Python JSONPath version 0.5.0, <code>count</code> is an alias for <code>length</code>. This might change in the future.</p> |
| 635 | +</div> |
570 | 636 | <h2 id="length"><code>length()</code></h2> |
571 | | -<p>TODO:</p> |
| 637 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a>length(obj: object) -> Optional[int] |
| 638 | +</span></code></pre></div> |
| 639 | +<p>Return the number of items in the input object. If the object does not respond to Python's <code>len()</code> function, <code>None</code> is returned.</p> |
| 640 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a>$.categories[?length(@) > 1] |
| 641 | +</span></code></pre></div> |
| 642 | +<h2 id="match"><code>match()</code></h2> |
| 643 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a>match(obj: object, pattern: str) -> bool |
| 644 | +</span></code></pre></div> |
| 645 | +<p>Return <code>True</code> if <em>obj</em> is a string and is a full match to the regex <em>pattern</em>.</p> |
| 646 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a>$..products[?match(@.title, ".+ainers.+")] |
| 647 | +</span></code></pre></div> |
| 648 | +<p>If <em>pattern</em> is a string literal, it will be compiled at compile time, and raise a <code>JSONPathTypeError</code> at compile time if it's invalid.</p> |
| 649 | +<p>If <em>pattern</em> is a query and the result is not a valid regex, <code>False</code> is returned.</p> |
| 650 | +<h2 id="search"><code>search()</code></h2> |
| 651 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a>search(obj: object, pattern: str) -> bool |
| 652 | +</span></code></pre></div> |
| 653 | +<p>Return <code>True</code> if <em>obj</em> is a string and it contains the regexp <em>pattern</em>.</p> |
| 654 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-7-1"><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a>$..products[?search(@.title, "ainers")] |
| 655 | +</span></code></pre></div> |
| 656 | +<p>If <em>pattern</em> is a string literal, it will be compiled at compile time, and raise a <code>JSONPathTypeError</code> at compile time if it's invalid.</p> |
| 657 | +<p>If <em>pattern</em> is a query and the result is not a valid regex, <code>False</code> is returned.</p> |
| 658 | +<h2 id="value"><code>value()</code></h2> |
| 659 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-8-1"><a id="__codelineno-8-1" name="__codelineno-8-1" href="#__codelineno-8-1"></a>value(nodes: object) -> object | undefined |
| 660 | +</span></code></pre></div> |
| 661 | +<p>Return the first value from <em>nodes</em> resulting from a JSONPath query, if there is only one node, or <code>undefined</code> otherwise.</p> |
| 662 | +<div class="language-text highlight"><pre><span></span><code><span id="__span-9-1"><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a>$..products[?value(@.price) == 9] |
| 663 | +</span></code></pre></div> |
572 | 664 |
|
573 | 665 |
|
574 | 666 |
|
|
0 commit comments