JSON-Path-1.0.6000755001750001750 014612756433 12307 5ustar00tooktook000000000000README100644001750001750 60514612756433 13231 0ustar00tooktook000000000000JSON-Path-1.0.6This archive contains the distribution JSON-Path, version 1.0.6: search nested hashref/arrayref structures using JSONPath This software is copyright (c) 2024 by Aurelia Peters. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v6.031. Changes100644001750001750 661614612756433 13674 0ustar00tooktook000000000000JSON-Path-1.0.61.0.6 2024-04-26 11:58:01-05:00 America/Chicago [ Other ] - Correct POD Elvin Aslanov++ 1.0.5 2024-04-22 16:10:46-05:00 America/Chicago [ Other ] - Remove dependency on Tie::IxHash Bernhard Schmalhofer++ 1.0.4 2023-12-11 13:29:46-06:00 America/Chicago [ Other ] - Remove dependency on JSON::Parse Bernhard Schmalhofer++ - Replace my deadname with my proper name Aurelia Peters++ 1.0.3 2022-12-15 19:43:48-05:00 America/Chicago [ Bug Fixes ] - Fix unicode issue in POD David Escribano García++ - Fix use of quotes and escaped characters inside quoted text David Escribano García++ [ Other ] - Implement =~ operator to filter using regular expressions. David Escribano García++ 1.0.2 2022-09-06 10:13:31-05:00 America/Chicago [ Bug Fixes ] - Fix missing dependencies 1.0.1 2022-08-30 21:58:38-05:00 America/Chicago 1.0.0 2022-08-30 21:56:52-05:00 America/Chicago [ Bug Fixes ] - Fix filtering when there are nested structures. Fixes issue #35 David Escribano García++ [ Bug Fixes ] - Fix filtering using unary operators. Fixes issue #34 David Escribano García++ [ Other ] - No functional changes since 0.51, switch to semantic versioning. 0.51 2022-03-03 18:25:11-06:00 America/Chicago [ Other ] - Remove JSON, use JSON::MaybeXS throughout. Fixes issue #22 James Rapass++ - Remove Exporter and Exporter::Easy, use Exporter::Shiny throughout. Fixes issue #23 James Raspass++ - Remove unused Sys::Hostname dependency. Fixes issue #24 James Raspass++ - Remove Test::Deep, Test::More, and Test::Most, use Test2::V0 throughout. Fixes issue #25 James Raspass++ 0.5 2021-07-07 10:52:00-05:00 America/Chicago [ Bug Fixes ] - basic support for AND and OR operators Fixes issue #21 David Escribano García ++ 0.430 2021-01-27 23:34:50-06:00 America/Chicago [ Bug Fixes ] - multiple recursion (e.g. $..foo..bar) works properly. Fixes RT #122529 Thomas Helsel ++ - Non-array-like and non-hash-like refs work properly for paths and map. Fixes RT #123381 Patrick Cronin++ [ Other ] - Warnings at the calling line when attempting to set on a non-object via set() or value() as an lvalue 0.401 2017-07-20 09:24:14-05:00 America/Chicago [ Other ] Changes to build files only 0.400 2017-07-17 17:44:44-05:00 America/Chicago [ Other ] Tokenizer has been rewritten and is now cleaner and 20% cooler. [ Bug Fixes ] - get() no longer creates keys in the object Fixes RT #122493 Thomas Helsel++ - Fix for path construction failure when expression contains a filter Fixes RT 122190 James Bowery++ 0.310 2017-07-11 13:36:54-05:00 America/Chicago [ Bug Fixes ] - Fixes RT #122427 Slaven Rezic++ 0.301 2017-07-10 16:37:15-05:00 America/Chicago [ Bug Fixes ] - Fix missing version information in main module 0.300 2017-07-10 11:13:48-05:00 America/Chicago [ Bug Fixes ] - Add support for escaping reserved characters Fixes RT #92237 Max Laager++ [ Other ] - Setting values on non-existent keys will create the key with the value - Forked from Toby Inkster's JSON::Path 0.205 LICENSE100644001750001750 4643514612756433 13431 0ustar00tooktook000000000000JSON-Path-1.0.6This software is copyright (c) 2024 by Aurelia Peters. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2024 by Aurelia Peters. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Perl Artistic License 1.0 --- This software is Copyright (c) 2024 by Aurelia Peters. This is free software, licensed under: The Perl Artistic License 1.0 The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End cpanfile100644001750001750 40314612756433 14051 0ustar00tooktook000000000000JSON-Path-1.0.6requires 'Carp::Assert'; requires 'Exporter::Tiny'; requires 'JSON::MaybeXS'; requires 'LV'; requires 'List::Util' => '1.45'; # For uniq. requires 'Readonly'; requires 'Try::Tiny'; requires 'perl' => '5.010'; on test => sub { requires 'Test2::V0'; }; dist.ini100644001750001750 104114612756433 14030 0ustar00tooktook000000000000JSON-Path-1.0.6name = JSON-Path author = Aurelia Peters license = Perl_5 copyright_holder = Aurelia Peters copyright_year = 2024 ; authordep Pod::Elemental::Transformer::List version = 1.0.6 [Prereqs::FromCPANfile] [@Basic] [MetaJSON] [GithubMeta] issues = 1 user = popefelix ;[@Git] [PodWeaver] [PkgVersion] [CheckChangeLog] [ ReadmeAnyFromPod / MarkdownInRoot ] filename = README.md [NextRelease] [MetaProvides::Package] ;[Git::Check] ;allow_dirty = dist.ini ;allow_dirty = META.json ;allow_dirty = README.md ;build_warnings = 1 META.yml100644001750001750 232514612756433 13643 0ustar00tooktook000000000000JSON-Path-1.0.6--- abstract: 'search nested hashref/arrayref structures using JSONPath' author: - 'Aurelia Peters ' build_requires: Test2::V0: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.031, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: JSON-Path provides: JSON::Path: file: lib/JSON/Path.pm version: v1.0.6 JSON::Path::Constants: file: lib/JSON/Path/Constants.pm version: v1.0.6 JSON::Path::Evaluator: file: lib/JSON/Path/Evaluator.pm version: v1.0.6 JSON::Path::Tokenizer: file: lib/JSON/Path/Tokenizer.pm version: v1.0.6 requires: Carp::Assert: '0' Exporter::Tiny: '0' JSON::MaybeXS: '0' LV: '0' List::Util: '1.45' Readonly: '0' Try::Tiny: '0' perl: '5.010' resources: bugtracker: https://github.com/popefelix/p5-json-path/issues homepage: https://github.com/popefelix/p5-json-path repository: https://github.com/popefelix/p5-json-path.git version: 1.0.6 x_generated_by_perl: v5.38.2 x_serialization_backend: 'YAML::Tiny version 1.74' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' MANIFEST100644001750001750 425414612756433 13526 0ustar00tooktook000000000000JSON-Path-1.0.6# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.031. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README build/Dockerfile cpanfile dist.ini examples/eg1.pl issues/issue48/Dockerfile jsonpath-compliance-test-suite/CODE_OF_CONDUCT.md jsonpath-compliance-test-suite/CONTRIBUTING.md jsonpath-compliance-test-suite/LICENSE jsonpath-compliance-test-suite/NOTICE jsonpath-compliance-test-suite/README.md jsonpath-compliance-test-suite/build.js jsonpath-compliance-test-suite/build.ps1 jsonpath-compliance-test-suite/build.sh jsonpath-compliance-test-suite/cts.json jsonpath-compliance-test-suite/cts.schema.json jsonpath-compliance-test-suite/tests/basic.json jsonpath-compliance-test-suite/tests/filter.json jsonpath-compliance-test-suite/tests/functions/count.json jsonpath-compliance-test-suite/tests/functions/length.json jsonpath-compliance-test-suite/tests/functions/match.json jsonpath-compliance-test-suite/tests/functions/search.json jsonpath-compliance-test-suite/tests/functions/value.json jsonpath-compliance-test-suite/tests/index_selector.json jsonpath-compliance-test-suite/tests/name_selector.json jsonpath-compliance-test-suite/tests/slice_selector.json jsonpath-compliance-test-suite/tests/whitespace/filter.json jsonpath-compliance-test-suite/tests/whitespace/functions.json jsonpath-compliance-test-suite/tests/whitespace/operators.json jsonpath-compliance-test-suite/tests/whitespace/selectors.json jsonpath-compliance-test-suite/tests/whitespace/slice.json lib/JSON/Path.pm lib/JSON/Path/Constants.pm lib/JSON/Path/Evaluator.pm lib/JSON/Path/Tokenizer.pm meta/changes.pret meta/doap.pret meta/makefile.pret t/01basic.t t/02zeroth.t t/03shortcuts.t t/04map.t t/05set.t t/06lvalue.t t/07utf8.t t/08context.t t/dots_in_path.t t/evaluator/path-construction-fail.t t/evaluator/paths.t t/evaluator/refs.t t/evaluator/tokenize.t t/evaluator/want_path.t t/filter_expression_and_or.t t/filter_expression_nested_objects.t t/filter_expression_regex.t t/hashref_not_modified.t t/multiple-recursion.t t/path-construction-failure.t t/quotes-in-filter-expression.t weaver.ini xt/01pod.t xt/02pod_coverage.t xt/03meta_uptodate.config xt/03meta_uptodate.t xt/04eol.t xt/06versions.t t000755001750001750 014612756433 12473 5ustar00tooktook000000000000JSON-Path-1.0.605set.t100644001750001750 356614612756433 13772 0ustar00tooktook000000000000JSON-Path-1.0.6/t =head1 PURPOSE Exercise C<< JSON::Path::set >>. =head1 SEE ALSO L. =head1 AUTHOR Mitsuhiro Nakamura =head1 COPYRIGHT AND LICENCE Copyright 2013 Mitsuhiro Nakamura. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =cut use Test2::V0; use JSON::Path -all; use JSON::MaybeXS; my $object = decode_json(<<'JSON'); { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } } JSON my $titles = '$.store.book[*].title'; my $jpath = JSON::Path->new($titles); is( [ $jpath->values($object) ], [ "Sayings of the Century", "Sword of Honour", "Moby Dick", "The Lord of the Rings", ] ); is( $jpath->set( $object => 'TBD', 2 ), 2, ); is( [ $jpath->values($object) ], [ "TBD", "TBD", "Moby Dick", "The Lord of the Rings", ], ); my $author = '$.store.book[2].author'; $jpath = JSON::Path->new($author); is( $jpath->value($object), "Herman Melville", ); is( $jpath->set( $object => 'Anon' ), 1, ); is( $jpath->value($object), 'Anon', ); $jpath = JSON::Path->new('$.store.book.0.publisher'); is( $jpath->set( $object, 'Peculiar Publications' ), 1 ); is( $jpath->value( $object ), 'Peculiar Publications' ); done_testing; 04map.t100644001750001750 320414612756433 13740 0ustar00tooktook000000000000JSON-Path-1.0.6/t =head1 PURPOSE Test C exported function. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE Copyright 2012-2013 Toby Inkster. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =cut use Test2::V0; use JSON::Path -all; use JSON::MaybeXS; my $object = decode_json(<<'JSON'); { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 }, "boolean": false } } JSON my $path1 = '$.store.book[*].title'; jpath_map { uc $_ } $object, '$.store.book[*].title'; is( [ jpath1( $object, $path1 ) ], [ map uc, 'Sayings of the Century' ], ); is( [ jpath( $object, $path1 ) ], [ map uc, 'Sayings of the Century', 'Sword of Honour', 'Moby Dick', 'The Lord of the Rings' ], ); is( JSON::Path->new('$.store.book[*].author')->set( $object => 'Anon', 2 ), 2, ); is( [ jpath( $object, '$.store.book[*].author' ) ], [ 'Anon', 'Anon', 'Herman Melville', 'J. R. R. Tolkien' ], ); done_testing(); META.json100644001750001750 400514612756433 14010 0ustar00tooktook000000000000JSON-Path-1.0.6{ "abstract" : "search nested hashref/arrayref structures using JSONPath", "author" : [ "Aurelia Peters " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.031, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "JSON-Path", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp::Assert" : "0", "Exporter::Tiny" : "0", "JSON::MaybeXS" : "0", "LV" : "0", "List::Util" : "1.45", "Readonly" : "0", "Try::Tiny" : "0", "perl" : "5.010" } }, "test" : { "requires" : { "Test2::V0" : "0" } } }, "provides" : { "JSON::Path" : { "file" : "lib/JSON/Path.pm", "version" : "v1.0.6" }, "JSON::Path::Constants" : { "file" : "lib/JSON/Path/Constants.pm", "version" : "v1.0.6" }, "JSON::Path::Evaluator" : { "file" : "lib/JSON/Path/Evaluator.pm", "version" : "v1.0.6" }, "JSON::Path::Tokenizer" : { "file" : "lib/JSON/Path/Tokenizer.pm", "version" : "v1.0.6" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/popefelix/p5-json-path/issues" }, "homepage" : "https://github.com/popefelix/p5-json-path", "repository" : { "type" : "git", "url" : "https://github.com/popefelix/p5-json-path.git", "web" : "https://github.com/popefelix/p5-json-path" } }, "version" : "1.0.6", "x_generated_by_perl" : "v5.38.2", "x_serialization_backend" : "Cpanel::JSON::XS version 4.37", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } weaver.ini100644001750001750 5614612756433 14323 0ustar00tooktook000000000000JSON-Path-1.0.6[@Default] [-Transformer] transformer = List xt000755001750001750 014612756433 12663 5ustar00tooktook000000000000JSON-Path-1.0.604eol.t100644001750001750 4414612756433 14071 0ustar00tooktook000000000000JSON-Path-1.0.6/xtuse Test::EOL; all_perl_files_ok(); 01pod.t100644001750001750 20214612756433 14105 0ustar00tooktook000000000000JSON-Path-1.0.6/xtuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); 07utf8.t100644001750001750 270214612756433 14056 0ustar00tooktook000000000000JSON-Path-1.0.6/t =head1 PURPOSE Some basic Tests for handling of unicode characters in JSON data. =head1 AUTHOR Heiko Jansen Ehjansen@cpan.orgE. =head1 COPYRIGHT AND LICENCE Copyright 2016 Heiko Jansen. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =cut use Test2::V0 '-target' => 'JSON::Path'; use JSON::MaybeXS; my $data = <<"JSON"; { "store": { "book": [ { "category": "reference", "author": "Randal L. Schwartz", "title": "Einf\xFChrung in Perl", "isbn": "9783868991451", "price": 34.90 }, { "category": "chartest", "author": "\x{61}\x{0300}\x{0320}. u. thor", "title": "Me \x{2661} Unicode", "price": 0.0 } ], "bicycle": { "color": "r\xF6tlich", "price": 19.95 } } } JSON utf8::encode($data); my $object = decode_json($data); my $path1 = JSON::Path->new('$.store.book[0].title'); is( "$path1", '$.store.book[0].title', "overloaded stringification" ); my @results1 = $path1->values($object); is( $results1[0], "Einf\xFChrung in Perl", "basic value result" ); @results1 = $path1->paths($object); is( $results1[0], "\$['store']['book']['0']['title']", "basic path result" ); my $path2 = JSON::Path->new('$.store.book[1].author'); my @results2 = $path2->values($object); is( $results2[0], "\x{61}\x{0300}\x{0320}. u. thor", "basic value result" ); done_testing; 01basic.t100644001750001750 455514612756433 14253 0ustar00tooktook000000000000JSON-Path-1.0.6/t =head1 PURPOSE Some basic JSON Path selection tests, including some using C, checking that its disallowed by default but can be switched on using the C<< $JSON::Path::Safe >> package variable. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE Copyright 2010-2013 Toby Inkster. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =cut use Test2::V0 '-target' => 'JSON::Path'; use JSON::MaybeXS; my $object = decode_json(<<'JSON'); { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } } JSON my $path1 = JSON::Path->new('$.store.book[0].title'); is( "$path1", '$.store.book[0].title', "overloaded stringification" ); my @results1 = $path1->values($object); is( $results1[0], 'Sayings of the Century', "basic value result" ); @results1 = $path1->paths($object); is( $results1[0], "\$['store']['book']['0']['title']", "basic path result" ); my $path2 = JSON::Path->new('$..book[-1:]'); my ($results2) = $path2->values($object); is( ref $results2, 'HASH', "hashref value result" ); is( $results2->{isbn}, "0-395-19395-8", "hashref seems to be correct" ); ok( $JSON::Path::Safe, "safe by default" ); ok( !eval { my $path3 = JSON::Path->new('$..book[?($_->{author} =~ /tolkien/i)]'); my $results3 = $path3->values($object); 1; }, "eval disabled by default" ); $JSON::Path::Safe = 0; my $path3 = JSON::Path->new('$..book[?($_->{author} =~ /tolkien/i)]'); my ($results3) = $path3->values($object); # TODO #is( ref $results3, 'HASH', "dangerous hashref value result" ); #is( $results3->{isbn}, "0-395-19395-8", "dangerous hashref seems to be correct" ); done_testing; Makefile.PL100644001750001750 247414612756433 14351 0ustar00tooktook000000000000JSON-Path-1.0.6# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.031. use strict; use warnings; use 5.010; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "search nested hashref/arrayref structures using JSONPath", "AUTHOR" => "Aurelia Peters ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "JSON-Path", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.010", "NAME" => "JSON::Path", "PREREQ_PM" => { "Carp::Assert" => 0, "Exporter::Tiny" => 0, "JSON::MaybeXS" => 0, "LV" => 0, "List::Util" => "1.45", "Readonly" => 0, "Try::Tiny" => 0 }, "TEST_REQUIRES" => { "Test2::V0" => 0 }, "VERSION" => "1.0.6", "test" => { "TESTS" => "t/*.t t/evaluator/*.t" } ); my %FallbackPrereqs = ( "Carp::Assert" => 0, "Exporter::Tiny" => 0, "JSON::MaybeXS" => 0, "LV" => 0, "List::Util" => "1.45", "Readonly" => 0, "Test2::V0" => 0, "Try::Tiny" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 02zeroth.t100644001750001750 241714612756433 14501 0ustar00tooktook000000000000JSON-Path-1.0.6/t =head1 PURPOSE Check the zeroth array element can be selected. =head1 SEE ALSO L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE Copyright 2011-2013 Toby Inkster. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =cut use Test2::V0 '-target' => 'JSON::Path'; use JSON::MaybeXS; my $object = { # 'foo' => [ # { 'bar' => 1, }, { 'bar' => 2, }, { 'bar' => 3, }, ] }; my $jpath1 = JSON::Path->new('$.foo[0]'); my @values1 = $jpath1->values( encode_json($object) ); is( scalar @values1, 1, 'Only returned a single result.' ); my $jpath2 = JSON::Path->new('$.foo[0,1]'); my @values2 = $jpath2->values( encode_json($object) ); is( scalar @values2, 2, 'Returned two results.' ); my $jpath3 = JSON::Path->new('$.foo[1:3]'); my @values3 = $jpath3->values( encode_json($object) ); is( scalar @values3, 2, 'Returned two results.' ); my $jpath4 = JSON::Path->new('$.foo[-1:]'); my @values4 = $jpath4->values( encode_json($object) ); is( scalar @values4, 1, 'Returned one result.' ); is( $values4[0]->{bar}, 3, 'Correct result.' ); done_testing; 06lvalue.t100644001750001750 231514612756433 14457 0ustar00tooktook000000000000JSON-Path-1.0.6/t =head1 PURPOSE Basic tests for some of the lvalue stuff. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE Copyright 2013 Toby Inkster. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =cut use Test2::V0; use JSON::Path -all; my $person = { name => "Robert", foo => { bar => [ 1, 2, 3 ] } }; my $path = JSON::Path->new('$.name'); $path->value($person) = "Bob"; is( $person, { name => "Bob", foo => { bar => [ 1, 2, 3 ] } } , q{Setting 'name' changes only the 'name' key and nothing else}); jpath1( $person, '$.name' ) = "Robbie"; jpath1( $person, '$.foo.bar' ) = 12; is( $person, { name => "Robbie", foo => { bar => 12 } }, q{jpath1() works as lvalue}); $path->value($person) ||= 'Fred'; is $person->{name}, 'Robbie', q{lvalue works with ||=}; $path = JSON::Path->new('$.quux'); $path->value($person) = 'alpha'; is $person->{quux}, 'alpha', q{lvalue will create keys not previously extant}; $path = JSON::Path->new('$.quuy'); $path->value($person) ||= 'beta'; is $person->{quuy}, 'beta', q{lvalue and ||= will create keys not previously extant}; done_testing; 08context.t100644001750001750 110014612756433 14644 0ustar00tooktook000000000000JSON-Path-1.0.6/tuse Test2::V0 '-target' => 'JSON::Path'; use JSON::MaybeXS; my $object = decode_json(<<'JSON'); { "elements": [ { "id": 1 }, { "id": 2 } ], "empty": null } JSON my $path1 = JSON::Path->new('$.elements[*]'); my @arr = $path1->values($object); is \@arr, [ { id => 1 }, { id => 2 } ], 'multiple values in list context'; my $scal = $path1->values($object); cmp_ok $scal, '==', 2, 'multiple values in scalar context'; my $path2 = JSON::Path->new('$.empty'); ok !!$path2->values($object), 'boolean check for existing null is true'; done_testing(); meta000755001750001750 014612756433 13156 5ustar00tooktook000000000000JSON-Path-1.0.6doap.pret100644001750001750 162114612756433 15135 0ustar00tooktook000000000000JSON-Path-1.0.6/meta# This file contains general metadata about the project. @prefix : . `JSON-Path` :programming-language "Perl" ; :shortdesc "search nested hashref/arrayref structures using JSONPath"; :homepage ; :download-page ; :bug-database ; :repository [ a :GitRepository; :browse ]; :created 2010-07-28; :license ; :maintainer cpan:TOBYINK; :developer cpan:TOBYINK. dc:title "the same terms as the perl 5 programming language system itself". cpan:TOBYINK foaf:name "Toby Inkster"; foaf:mbox . examples000755001750001750 014612756433 14046 5ustar00tooktook000000000000JSON-Path-1.0.6eg1.pl100644001750001750 236514612756433 15225 0ustar00tooktook000000000000JSON-Path-1.0.6/examplesuse 5.010; use JSON::MaybeXS; use Scalar::Util qw[blessed]; use lib "../lib"; use JSON::Path; my $json = JSON::MaybeXS->new( pretty => 1 ); my $object = $json->decode(<<'JSON'); { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } } JSON $JSON::Path::Safe = 0; foreach ('$.store.book[0].title', '$.store.book[*].author', '$..author', '$..book[-1:]', '$..book[?($_->{author} =~ /tolkien/i)]') { my $jpath = JSON::Path->new($_); say $jpath; say $json->encode([$jpath->values($object)]); say $json->encode([$jpath->paths($object)]); say [$jpath->values($object)]->[0]->nodePath if blessed([$jpath->values($object)]->[0]); say '-' x 40; } 06versions.t100644001750001750 47014612756433 15207 0ustar00tooktook000000000000JSON-Path-1.0.6/xtuse XT::Util; use Test::More; use Test::HasVersion; plan skip_all => __CONFIG__->{skip_all} if __CONFIG__->{skip_all}; if ( __CONFIG__->{modules} ) { my @modules = @{ __CONFIG__->{modules} }; pm_version_ok($_, "$_ is covered") for @modules; done_testing(scalar @modules); } else { all_pm_version_ok(); } 03shortcuts.t100644001750001750 255414612756433 15227 0ustar00tooktook000000000000JSON-Path-1.0.6/t =head1 PURPOSE Test C and C exported functions. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE Copyright 2012-2013 Toby Inkster. This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =cut use Test2::V0; use JSON::Path -all; use JSON::MaybeXS; my $object = decode_json(<<'JSON'); { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } } JSON my $path1 = '$.store.book[*].title'; is( [ jpath1( $object, $path1 ) ], ['Sayings of the Century'], ); is( [ jpath( $object, $path1 ) ], [ 'Sayings of the Century', 'Sword of Honour', 'Moby Dick', 'The Lord of the Rings' ], ); done_testing(); JSON000755001750001750 014612756433 13547 5ustar00tooktook000000000000JSON-Path-1.0.6/libPath.pm100644001750001750 2766314612756433 15177 0ustar00tooktook000000000000JSON-Path-1.0.6/lib/JSONpackage JSON::Path; $JSON::Path::VERSION = '1.0.6'; use strict; use warnings; # VERSION use Exporter::Shiny qw/ jpath jpath1 jpath_map /; our $AUTHORITY = 'cpan:POPEFELIX'; our $Safe = 1; use Carp; use JSON::MaybeXS qw/decode_json/; use JSON::Path::Evaluator; use Scalar::Util qw[blessed]; use LV (); use overload '""' => \&to_string; sub jpath { my ( $object, $expression ) = @_; my @return = __PACKAGE__->new($expression)->values($object); } sub jpath1 : lvalue { my ( $object, $expression ) = @_; __PACKAGE__->new($expression)->value($object); } sub jpath_map (&$$) { my ( $coderef, $object, $expression ) = @_; return __PACKAGE__->new($expression)->map( $object, $coderef ); } sub new { my ( $class, $expression ) = @_; return $expression if blessed($expression) && $expression->isa(__PACKAGE__); return bless \$expression, $class; } sub to_string { my ($self) = @_; return $$self; } sub paths { my ( $self, $object ) = @_; my @paths = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_path => 1); return @paths; } sub get { my ( $self, $object ) = @_; my @values = $self->values($object); return wantarray ? @values : $values[0]; } sub set { my ( $self, $object, $value, $limit ) = @_; if ( !ref $object ) { # warn if not called internally. If called internally (i.e. from value()) we will already have warned. my @c = caller(0); if ( $c[1] !~ /JSON\/Path\.pm$/ ) { carp qq{Useless attempt to set a value on a non-reference}; } } my $count = 0; my @refs = JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", want_ref => 1 ); for my $ref (@refs) { ${$ref} = $value; ++$count; last if $limit && ( $count >= $limit ); } return $count; } sub value : lvalue { my ( $self, $object ) = @_; LV::lvalue( get => sub { my ($value) = $self->get($object); return $value; }, set => sub { my $value = shift; # do some caller() magic to warn at the right place if ( !ref $object ) { my @c = caller(2); my ( $filename, $line ) = @c[ 1, 2 ]; warn qq{Useless attempt to set a value on a non-reference at $filename line $line\n}; } $self->set( $object, $value, 1 ); }, ); } sub values { my ( $self, $object ) = @_; croak q{non-safe evaluation, died} if "$self" =~ /\?\(/ && $JSON::Path::Safe; return JSON::Path::Evaluator::evaluate_jsonpath( $object, "$self", script_engine => 'perl' ); } sub map { my ( $self, $object, $coderef ) = @_; my $count; foreach my $path ( $self->paths( $object ) ) { my ($ref) = JSON::Path::Evaluator::evaluate_jsonpath( $object, $path, want_ref => 1 ); ++$count; my $value = do { no warnings 'numeric'; local $_ = ${$ref}; local $. = $path; scalar $coderef->(); }; ${$ref} = $value; } return $count; } 1; __END__ =pod =encoding utf-8 =head1 NAME JSON::Path =head1 VERSION version 1.0.6 =head1 SYNOPSIS my $data = { "store" => { "book" => [ { "category" => "reference", "author" => "Nigel Rees", "title" => "Sayings of the Century", "price" => 8.95, }, { "category" => "fiction", "author" => "Evelyn Waugh", "title" => "Sword of Honour", "price" => 12.99, }, { "category" => "fiction", "author" => "Herman Melville", "title" => "Moby Dick", "isbn" => "0-553-21311-3", "price" => 8.99, }, { "category" => "fiction", "author" => "J. R. R. Tolkien", "title" => "The Lord of the Rings", "isbn" => "0-395-19395-8", "price" => 22.99, }, ], "bicycle" => [ { "color" => "red", "price" => 19.95, }, ], }, }; use JSON::Path 'jpath_map'; # All books in the store my $jpath = JSON::Path->new('$.store.book[*]'); my @books = $jpath->values($data); # The author of the last (by order) book my $jpath = JSON::Path->new('$..book[-1:].author'); my $tolkien = $jpath->value($data); # Convert all authors to uppercase jpath_map { uc $_ } $data, '$.store.book[*].author'; =head1 DESCRIPTION This module implements JSONPath, an XPath-like language for searching JSON-like structures. JSONPath is described at L. =head2 Constructor =over 4 =item C<< JSON::Path->new($string) >> Given a JSONPath expression C<$string>, returns a C object. =back =head2 Methods =over 4 =item C<< values($object) >> Evaluates the JSONPath expression against an object. The object $object can be either a nested Perl hashref/arrayref structure, or a JSON string capable of being decoded by JSON::MaybeXS::decode_json. Returns a list of structures from within $object which match against the JSONPath expression. In scalar context, returns the number of matches. =item C<< value($object) >> Like C, but returns just the first value. This method is an lvalue sub, which means you can assign to it: my $person = { name => "Robert" }; my $path = JSON::Path->new('$.name'); $path->value($person) = "Bob"; TAKE NOTE! This will create keys in $object. E.G.: my $obj = { foo => 'bar' }; my $path = JSON::Path->new('$.baz'); $path->value($obj) = 'bak'; # $obj->{baz} is created and set to 'bak'; =item C<< paths($object) >> As per C but instead of returning structures which match the expression, returns canonical JSONPaths that point towards those structures. =item C<< get($object) >> In list context, identical to C<< values >>, but in scalar context returns the first result. =item C<< set($object, $value, $limit) >> Alters C<< $object >>, setting the paths to C<< $value >>. If set, then C<< $limit >> limits the number of changes made. TAKE NOTE! This will create keys in $object. E.G.: my $obj = { foo => 'bar' }; my $path = JSON::Path->new('$.baz'); $path->set($obj, 'bak'); # $obj->{baz} is created and set to 'bak' Returns the number of changes made. =item C<< map($object, $coderef) >> Conceptually similar to Perl's C keyword. Executes the coderef (in scalar context!) for each match of the path within the object, and sets a new value from the coderef's return value. Within the coderef, C<< $_ >> may be used to access the old value, and C<< $. >> may be used to access the curent canonical JSONPath. =item C<< to_string >> Returns the original JSONPath expression as a string. This method is usually not needed, as the JSON::Path should automatically stringify itself as appropriate. i.e. the following works: my $jpath = JSON::Path->new('$.store.book[*].author'); print "I'm looking for: " . $jpath . "\n"; =back =head2 Functions The following functions are available for export, but are not exported by default: =over =item C<< jpath($object, $path_string) >> Shortcut for C<< JSON::Path->new($path_string)->values($object) >>. =item C<< jpath1($object, $path_string) >> Shortcut for C<< JSON::Path->new($path_string)->value($object) >>. Like C, it can be used as an lvalue. =item C<< jpath_map { CODE } $object, $path_string >> Shortcut for C<< JSON::Path->new($path_string)->map($object, $code) >>. =back =head1 NAME JSON::Path - search nested hashref/arrayref structures using JSONPath =head1 PERL SPECIFICS JSONPath is intended as a cross-programming-language method of searching nested object structures. There are however, some things you need to think about when using JSONPath in Perl... =head2 JSONPath Embedded Perl Expressions JSONPath expressions may contain subexpressions that are evaluated using the native host language. e.g. $..book[?($_->{author} =~ /tolkien/i)] The stuff between "?(" and ")" is a Perl expression that must return a boolean, used to filter results. As arbitrary Perl may be used, this is clearly quite dangerous unless used in a controlled environment. Thus, it's disabled by default. To enable, set: $JSON::Path::Safe = 0; There are some differences between the JSONPath spec and this implementation. =over 4 =item * JSONPath uses a variable '$' to refer to the root node. This is not a legal variable name in Perl, so '$root' is used instead. =item * JSONPath uses a variable '@' to refer to the current node. This is not a legal variable name in Perl, so '$_' is used instead. =back =head2 Blessed Objects Blessed objects are generally treated as atomic values; JSON::Path will not follow paths inside them. The exception to this rule are blessed objects where: Scalar::Util::blessed($object) && $object->can('typeof') && $object->typeof =~ /^(ARRAY|HASH)$/ which are treated as an unblessed arrayref or hashref appropriately. =head1 BUGS Please report any bugs to L. =head1 SEE ALSO Specification: L. Implementations in PHP, Javascript and C#: L. Jayway JsonPath: L Related modules: L, L, L, L, L, L. Similar functionality: L, L, L, L, L, L, L... yes, the idea's not especially new. What's different is that JSON::Path uses a vaguely standardised syntax with implementations in at least three other programming languages. =head1 AUTHOR Aurelia Peters L =head1 CONTRIBUTORS Toby Inkster https://github.com/tobyink Szymon Nieznański https://github.com/s-nez Heiko Jansen https://github.com/heikojansen Mitsuhiro Nakamura https://github.com/mnacamura David Escribano García https://github.com/DavidEGx Thomas Helsel https://github.com/thelsel Patrick Cronin https://github.com/PatrickCronin James Bowery https://github.com/jabowery Slaven Rezić https://github.com/eserte Max Laager https://github.com/mlaagerc2c Elvin Aslanov https://github.com/rwp0 James Raspass https://github.com/JRaspass Bernhard Schmalhofer https://github.com/bschmalhofer =head1 COPYRIGHT AND LICENCE Copyright 2007 Stefan Goessner. Copyright 2010-2013 Toby Inkster. Copyright 2021-2024 Aurelia Peters This module is tri-licensed. It is available under the X11 (a.k.a. MIT) licence; you can also redistribute it and/or modify it under the same terms as Perl itself. =head2 a.k.a. "The MIT Licence" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 AUTHOR Aurelia Peters =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2024 by Aurelia Peters. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut build000755001750001750 014612756433 13327 5ustar00tooktook000000000000JSON-Path-1.0.6Dockerfile100644001750001750 62114612756433 15440 0ustar00tooktook000000000000JSON-Path-1.0.6/buildFROM perl:stable ENV TZ="America/Chicago" RUN cpanm LWP::Protocol::https RUN cpanm Dist::Zilla Pod::Elemental::Transformer::List \ Dist::Zilla::Plugin::CheckChangeLog Dist::Zilla::Plugin::GithubMeta \ Dist::Zilla::Plugin::MetaProvides::Package Dist::Zilla::Plugin::PodWeaver \ Dist::Zilla::Plugin::Prereqs::FromCPANfile Dist::Zilla::Plugin::ReadmeAnyFromPod \ Carp::Assert LV Readonly dots_in_path.t100644001750001750 32214612756433 15450 0ustar00tooktook000000000000JSON-Path-1.0.6/tuse Test2::V0 '-target' => 'JSON::Path'; my $json = '{ "path.two" : "value.two", "path.one" : "value.one" }'; my $jpath = $CLASS->new('$.path\.one'); is $jpath->value($json), 'value.one'; done_testing; changes.pret100644001750001750 626314612756433 15631 0ustar00tooktook000000000000JSON-Path-1.0.6/meta# This file acts as the project's changelog. @prefix : . @prefix my: . my:v_0-080_00 a :Version ; dc:issued "2010-07-28"^^xsd:date ; :revision "0.080_00"^^xsd:string ; :file-release ; rdfs:label "Ported from PHP."@en . my:v_0-080_01 a :Version ; dc:issued "2010-07-29"^^xsd:date ; :revision "0.080_01"^^xsd:string ; :file-release ; dcs:changeset [ dcs:versus my:v_0-080_00 ; dcs:item [ rdfs:label "Fix license metadata in distribution."@en ; a dcs:Bugfix ] ] . my:v_0-100 a :Version ; dc:issued "2010-08-25"^^xsd:date ; :revision "0.100"^^xsd:string ; :file-release ; dcs:changeset [ dcs:versus my:v_0-080_01 ; dcs:item [ rdfs:label "Support for JSON::JOM."@en ; a dcs:Update ] ; dcs:item [ rdfs:label "Minor documentation improvements."@en ] ; ] . my:v_0-101 a :Version ; dc:issued "2011-09-29"^^xsd:date ; :revision "0.101"^^xsd:string ; :file-release ; dcs:changeset [ dcs:versus my:v_0-100 ; dcs:item [ rdfs:label "Fix retrieval of zeroth array element."@en ; a dcs:Bugfix ] ; dcs:item [ rdfs:label "Add more test cases."@en ; a dcs:Packaging ] ; ] . my:project :release my:v_0-080_00, my:v_0-080_01, my:v_0-100, my:v_0-101. # Pretdsl below here... `JSON-Path 0.200 cpan:TOBYINK` issued 2012-09-12; changeset [ item "Switch from Error.pm exceptions to Carp::croak."^^Update; item "Drop dependency on common::sense."^^Packaging; item "Modernize."^^Packaging; ]. `JSON-Path 0.201 cpan:TOBYINK` issued 2012-09-12; changeset [ item "Remove remaining `use Error` in test suite."^^Bugfix; ]. `JSON-Path 0.202 cpan:TOBYINK` issued 2012-10-12; changeset [ item "`value` method."^^Addition; item "`map` method."^^Addition; item "`get` and `set` methods."^^Addition; item "`jpath`, `jpath1` and `jpath_map` functions."^^Addition; ]. `JSON-Path 0.203 cpan:TOBYINK` issued 2012-10-12; changeset [ item "Minor corrections to pod."^^Documentation; ]. `JSON-Path 0.204 cpan:TOBYINK` issued 2013-02-14; changeset [ item "Corrections to lvalue documentation."^^Documentation; item "Add documentation to test suite."^^Documentation; item [ a dcs:Bugfix; label "Fix `set` method which was broken in some circumstances."; dcs:fixes RT#83249; dcs:thanks [ a foaf:Person; foaf:name "Mitsuhiro Nakamura" ]; ]; ]. `JSON-Path 0.205 cpan:TOBYINK` issued 2013-11-02; changeset [ item "Use Dist::Inkt."^^Packaging; item "Use LV instead of lvalue.pm."^^Change; item "Use Exporter::Tiny instead of Sub::Exporter."^^Change; item [ a dcs:Bugfix; label "Fix problem using JSON::Path with Devel::ptkdb."; dcs:fixes RT#89393; dcs:thanks [ a foaf:Person; foaf:name "Henri-Damien Laurent" ]; ]; ]. makefile.pret100644001750001750 52614612756433 15752 0ustar00tooktook000000000000JSON-Path-1.0.6/meta# This file provides instructions for packaging. `JSON-Path` deps:runtime-requirement [ deps:on "JSON::MaybeXS 1.003005"^^deps:CpanId ]; deps:runtime-requirement [ deps:on "Exporter::Tiny"^^deps:CpanId ]; deps:runtime-requirement [ deps:on "LV"^^deps:CpanId ]; deps:test-requirement [ deps:on "Test::More 0.61"^^deps:CpanId ]; . evaluator000755001750001750 014612756433 14475 5ustar00tooktook000000000000JSON-Path-1.0.6/trefs.t100644001750001750 2046214612756433 16005 0ustar00tooktook000000000000JSON-Path-1.0.6/t/evaluatoruse Test2::V0 '-target' => 'JSON::Path::Evaluator'; use Carp; use JSON::MaybeXS qw/decode_json/; my @tests_to_run = split /,/, $ARGV[0] // ''; subtest recursive => sub { plan skip_all => 'This test not requested' if @tests_to_run && !grep { lc($_) eq 'recursive' } @tests_to_run; my @expressions = ( '$..book[-1:]' => single_ref( sub { $_[0]->{store}{book}[-1] } ), '$..foo' => sub { my ( $refs, $obj ) = @_; for ( 0 .. $#{$refs} ) { my $ref = $refs->[$_]; my $expected = int rand 1000; is ref $ref, 'SCALAR', qq{Reftype $_ OK}; ${$ref} = $expected; is $obj->{complex_array}[$_]{foo}, $expected, qq{Value $_ OK}; } }, '$..nonexistent' => sub { my ( $refs, $obj ) = @_; is scalar @{$refs}, 0, 'Nonexistent recursive path gives nothing back'; }, ); while ( my $expression = shift @expressions ) { my $test = shift @expressions; do_test( $expression, $test ); } }; subtest filtering => sub { if ( @tests_to_run && !grep { lc($_) eq 'filtering' } @tests_to_run ) { plan skip_all => 'This test not requested'; } my @expressions = ( '$.complex_array[?(@.quux)]' => sub { my ( $refs, $obj ) = @_; my @indices = grep { $obj->{complex_array}[$_]{quux} } ( 0 .. $#{ $obj->{complex_array} } ); for ( 0 .. $#{$refs} ) { my $ref = $refs->[$_]; my $expected = int rand 1000; ${$ref} = $expected; is $obj->{complex_array}[ $indices[$_] ], $expected, q{Value OK}; } }, '$.complex_array[?(@.type.code=="CODE_ALPHA")]' => single_ref( sub { $_[0]->{complex_array}[0] } ), ); while ( my $expression = shift @expressions ) { my $test = shift @expressions; do_test( $expression, $test ); } }; subtest simple => sub { plan skip_all => 'This test not requested' if @tests_to_run && !grep { lc($_) eq 'simple' } @tests_to_run; my @expressions = ( '$.array[-1:]' => single_ref( sub { $_[0]->{array}[-1] } ), '$.simple' => single_ref( sub { $_[0]->{simple} } ), '$.boolean' => single_ref( sub { $_[0]->{boolean} } ), '$.long_hash.key1.subkey2' => single_ref( sub { $_[0]->{long_hash}{key1}{subkey2} } ), '$.multilevel_array.1.0.0' => single_ref( sub { $_[0]->{multilevel_array}[1][0][0] } ), '$.store.book[0].title' => single_ref( sub { $_[0]->{store}{book}[0]{title} } ), '$.array[0]' => single_ref( sub { $_[0]->{array}[0] } ), '$.long_hash.key1' => single_ref( sub { $_[0]->{long_hash}{key1} } ), '$.nonexistent' => sub { my ( $refs, $obj ) = @_; ok exists $obj->{nonexistent}, 'want_ref creates the key'; }, ); while ( my $expression = shift @expressions ) { my $test = shift @expressions; do_test( $expression, $test ); } }; subtest 'union, slice, and all' => sub { plan skip_all => 'This test not requested' if @tests_to_run && !grep { lc($_) eq 'union' } @tests_to_run; my @expressions = ( '$.store.book[*].title' => sub { my ( $refs, $obj ) = @_; for ( 0 .. $#{$refs} ) { my $ref = $refs->[$_]; my $expected = int rand 1000; is ref $ref, 'SCALAR', qq{Reftype $_ OK}; ${$ref} = $expected; is $obj->{store}{book}[$_]{title}, $expected, qq{Value $_ OK}; } }, '$.long_hash.key1[subkey1,subkey2]' => sub { my ( $refs, $obj ) = @_; for ( 0 .. $#{$refs} ) { my $ref = $refs->[$_]; my $expected = int rand 1000; is ref $ref, 'SCALAR', qq{Reftype $_ OK}; ${$ref} = $expected; if ( $_ == 0 ) { is $obj->{long_hash}{key1}{subkey1}, $expected, q{Value for 'subkey1' OK}; } else { is $obj->{long_hash}{key1}{subkey2}, $expected, q{Value for 'subkey2' OK}; } } }, '$.array[0,1]' => sub { my ( $refs, $obj ) = @_; for ( 0 .. $#{$refs} ) { my $ref = $refs->[$_]; my $expected = int rand 1000; is ref $ref, 'SCALAR', qq{Reftype $_ OK}; ${$ref} = $expected; is $obj->{array}[$_], $expected, qq{Value $_ OK}; } }, '$.array[1:3]' => sub { my ( $refs, $obj ) = @_; for ( 0 .. $#{$refs} ) { my $ref = $refs->[$_]; my $expected = int rand 1000; is ref $ref, 'SCALAR', qq{Reftype $_ OK}; ${$ref} = $expected; is $obj->{array}[ $_ + 1 ], $expected, qq{Value $_ OK}; } }, ); while ( my $expression = shift @expressions ) { my $test = shift @expressions; do_test( $expression, $test ); } }; done_testing; sub do_test { my ( $expression, $test ) = @_; my $json = sample_json(); my $obj = decode_json($json); subtest $expression => sub { my @refs; ok lives { @refs = JSON::Path::Evaluator::evaluate_jsonpath( $obj, $expression, want_ref => 1 ) }, q{evaluate() did not die}; $test->( \@refs, $obj ); }; } sub single_ref { my $path = shift; return sub { my ( $refs, $obj ) = @_; my ($ref) = @{$refs}; my $expected = int rand 1000; ${$ref} = $expected; is $path->($obj), $expected, q{Value OK}; }; } sub sample_json { my $data = < __CONFIG__->{skip_all} if __CONFIG__->{skip_all}; if ( __CONFIG__->{modules} ) { my @modules = @{ __CONFIG__->{modules} }; pod_coverage_ok($_, "$_ is covered") for @modules; done_testing(scalar @modules); } else { all_pod_coverage_ok(); } paths.t100644001750001750 1354014612756433 16164 0ustar00tooktook000000000000JSON-Path-1.0.6/t/evaluatoruse Test2::V0; use JSON::MaybeXS qw/encode_json decode_json/; use JSON::Path::Evaluator; use Storable qw(dclone); my $json = sample_json(); my %data = %{ decode_json($json) }; subtest filter => sub { my @expressions = ( '$..[?(@.price > 10)]' => [ grep { $_->{price} > 10 } @{ $data{store}{book} } ], '$.complex_array[?(@.weight > 10)]' => [ map { dclone $_ } grep { $_->{weight} > 10 } @{ $data{complex_array} } ], '$.complex_array[?($_->{weight} > 10)]' => [ map { dclone $_ } grep { $_->{weight} > 10 } @{ $data{complex_array} } ], '$.complex_array[?(@.type.code=="CODE_ALPHA")]' => [ dclone( ( grep { $_->{type}{code} eq 'CODE_ALPHA' } @{ $data{complex_array} } )[0] ) ], '$.complex_array[?(@.weight > 10)].classification.quux' => [ map { $_->{classification}{quux} } grep { $_->{weight} > 10 } @{ $data{complex_array} } ], '$.complex_array[?(@.quux)]' => [ grep { $_->{quux} } @{ $data{complex_array} } ], ); do_test(@expressions); }; subtest simple => sub { my @expressions = ( '$.nonexistent' => [ ], '$.simple' => [ $data{simple} ], '$.boolean' => [ $data{boolean} ], '$.long_hash.key1.subkey2' => [ $data{long_hash}{key1}{subkey2} ], '$.long_hash.key1' => [ dclone $data{long_hash}{key1} ], q{$.complex_array[0]['foo']} => [ $data{complex_array}[0]{foo} ], '$.multilevel_array.1.0.0' => [ $data{multilevel_array}->[1][0][0] ], '$.multilevel_array.0.1[0]' => [ $data{multilevel_array}->[0][1][0] ], '$.multilevel_array[0][0][1]' => [ $data{multilevel_array}->[0][0][1] ], '$.store.book[0].title' => [ $data{store}{book}->[0]{title} ], '$.array[0]' => [ $data{array}->[0] ], ); do_test(@expressions); }; subtest all => sub { my @expressions = ( '$.*' => [ map { ref $_ ? dclone $_ : $_ } values %data ], '$.store.book[*].title' => [ map { $_->{title} } @{ $data{store}{book} } ], ); do_test(@expressions); }; subtest recursive => sub { my @expressions = ( '$..nonexistent' => [], '$..foo' => [qw/bar baz bak/], '$..complex_array[?(@.weight > 10)].classification.quux' => [ map { $_->{classification}{quux} } grep { $_->{weight} > 10 } @{ $data{complex_array} } ], '$..key2.subkey1' => ['2value1'], '$..book[-1:]' => [ $data{store}{book}->[-1] ], ); do_test(@expressions); }; subtest 'slice and union' => sub { my @expressions = ( '$.array[0,1]' => [ @{ $data{array} }[ ( 0, 1 ) ] ], '$.array[1:3]' => [ @{ $data{array} }[ ( 1 .. 2 ) ] ], '$.array[-1:]' => [ $data{array}->[-1] ], '$.long_hash.key1[subkey1,subkey2]' => [ @{ $data{long_hash}{key1} }{qw/subkey1 subkey2/} ], ); do_test(@expressions); }; done_testing; sub do_test { my @expressions = @_; while ( my $expression = shift @expressions ) { my $expected = shift @expressions; subtest $expression => sub { my @got; ok lives { @got = JSON::Path::Evaluator::evaluate_jsonpath( $json, $expression ); }, 'lives'; is \@got, bag { item $_ for @$expected; end }, 'evaluated correctly'; }; } } sub sample_json { my $data = < 1; use Test::RDF::DOAP::Version; doap_version_ok(__CONFIG__->{package}, __CONFIG__->{version_from}); multiple-recursion.t100644001750001750 61514612756433 16644 0ustar00tooktook000000000000JSON-Path-1.0.6/tuse Test2::V0 '-target' => 'JSON::Path'; use JSON::MaybeXS; # Test for RT #122529 my $to_find = '$..foo..value'; my $doc = '{"foo":{"value":3}}'; my $jpath = $CLASS->new($to_find); my @found = $jpath->paths($doc); is( \@found, [q{$['foo']['value']}], 'Path correct' ); my $hash = decode_json($doc); $jpath->value($hash) = 4; is $hash->{foo}{value}, 4, 'value correct'; done_testing(); tokenize.t100644001750001750 371514612756433 16660 0ustar00tooktook000000000000JSON-Path-1.0.6/t/evaluatoruse Test2::V0; use JSON::Path::Tokenizer qw(tokenize); my @EXPRESSIONS = ( q{$[1:3:2].foobar} => [qw/$ [ 1:3:2 ] . foobar/], q{$.[0].title} => [qw/$ . [ 0 ] . title/], q{$.store.book[?(@.price < 10)].title} => [ qw/$ . store . book [?(/, '@.price < 10', qw/)] . title/ ], '$.[*].id' => [qw/$ . [ * ] . id/], q{$.[1].title} => [qw/$ . [ 1 ] . title/], q{$..labels[?(@.name==bug)]} => [qw/$ .. labels [?( @.name==bug )]/], q{$.store.book[(@.length-1)].title} => [qw/$ . store . book [( @.length-1 )] . title/], q{$.store.book[?(@.price < 10)].title} => [ qw/$ . store . book [?(/, '@.price < 10', qw/)] . title/ ], q{$.store.book[?(@.price <= 10)].title} => [ qw/$ . store . book [?(/, '@.price <= 10', qw/)] . title/ ], q{$.store.book[?(@.price >= 10)].title} => [ qw/$ . store . book [?(/, '@.price >= 10', qw/)] . title/ ], q{$.store.book[?(@.price === 10)].title} => [ qw/$ . store . book [?(/, '@.price === 10', qw/)] . title/ ], q{$['store']['book'][0]['author']} => [ '$', '[', q(store), ']', '[', q(book), ']', '[', 0, ']', '[', q(author), ']' ], q{$['store']['book'][1]['author']} => [ '$', '[', q(store), ']', '[', q(book), ']', '[', 1, ']', '[', q(author), ']' ], q{$.[*].user[?(@.login == 'laurilehmijoki')]} => [ qw/$ . [ * ] . user [?(/, q{@.login == 'laurilehmijoki'}, ')]' ], q{$.path\.one.two} => [qw/$ . path.one . two/], q{$.'path.one'.two} => [qw/$ . path.one . two/], ); for ( 0 .. ( $#EXPRESSIONS / 2 ) ) { my $expression = $EXPRESSIONS[ $_ * 2 ]; my $expected = $EXPRESSIONS[ $_ * 2 + 1 ]; my $tokens; subtest $expression => sub { ok lives { $tokens = [ tokenize($expression) ] }, q{tokenize() did not die}; is $tokens, $expected, q{Token stream correct}; }; } done_testing; want_path.t100644001750001750 406114612756433 17010 0ustar00tooktook000000000000JSON-Path-1.0.6/t/evaluatoruse Test2::V0 '-target' => 'JSON::Path::Evaluator'; use JSON::MaybeXS; my $json = q({ "store" : { "book" : [ { "price" : 8.95, "title" : "Sayings of the Century", "author" : "Nigel Rees", "category" : "reference" }, { "price" : 12.99, "title" : "Sword of Honour", "author" : "Evelyn Waugh", "category" : "fiction" }, { "price" : 8.99, "isbn" : "0-553-21311-3", "title" : "Moby Dick", "author" : "Herman Melville", "category" : "fiction" }, { "price" : 22.99, "isbn" : "0-395-19395-8", "title" : "The Lord of the Rings", "author" : "J. R. R. Tolkien", "category" : "fiction" } ], "open_for_the_holidays": false } }); my $obj = decode_json($json); my @expressions = ( q{$..[?(@.price > 10)]} => [ q{$['store']['book']['1']}, q{$['store']['book']['3']}, ], q{$.store.book.0.price} => q{$['store']['book']['0']['price']}, q{$.store.book[?($_->{author} eq "J. R. R. Tolkien")]} => q{$['store']['book']['3']}, q{$.store.book[?($_->{category} eq "fiction")]} => [ q{$['store']['book']['1']}, q{$['store']['book']['2']}, q{$['store']['book']['3']} ], q{$.store.open_for_the_holidays} => q{$['store']['open_for_the_holidays']}, ); do_test(@expressions); done_testing; sub do_test { my @expressions = @_; while ( my $expression = shift @expressions ) { subtest $expression => sub { my $expected = shift @expressions; $expected = [$expected] unless ref $expected eq 'ARRAY'; my @got; ok lives { @got = JSON::Path::Evaluator::evaluate_jsonpath( $json, $expression, want_path => 1 ); }, q{evaluate_jsonpath did not die} or diag qq{Caught exception $@}; is \@got, $expected, qq{"$expression" evaluated correctly}; }; } } hashref_not_modified.t100644001750001750 57414612756433 17146 0ustar00tooktook000000000000JSON-Path-1.0.6/tuse Test2::V0 '-target' => 'JSON::Path'; # Test demonstrating RT 122493, "Changed behavior - get() returns an array with a single, undef element when no results are found" # https://rt.cpan.org/Ticket/Display.html?id=122493 my $orig = { bar => 1 }; my $p = JSON::Path->new("\$foo"); my $res = $p->get($orig); is( $orig, { bar => 1 }, "hashref is unchanged"); done_testing(); issue48000755001750001750 014612756433 15047 5ustar00tooktook000000000000JSON-Path-1.0.6/issuesDockerfile100644001750001750 52514612756433 17163 0ustar00tooktook000000000000JSON-Path-1.0.6/issues/issue48FROM centos:7 ENV TZ="America/Chicago" RUN yum update -y RUN yum install which -y RUN yum install perl-core -y RUN yum install gcc -y RUN yum install make -y RUN NONINTERACTIVE=1 bash -c "curl -L https://cpanmin.us | perl - App::cpanminus" RUN cpanm JSON::Path CMD perl -MJSON::Path -e 'print "JSON::Path v" . $JSON::Path::VERSION . "\n";' 03meta_uptodate.config100644001750001750 3014612756433 17141 0ustar00tooktook000000000000JSON-Path-1.0.6/xt{"package":"JSON-Path"} Path000755001750001750 014612756433 14443 5ustar00tooktook000000000000JSON-Path-1.0.6/lib/JSONTokenizer.pm100644001750001750 1364514612756433 17144 0ustar00tooktook000000000000JSON-Path-1.0.6/lib/JSON/Pathpackage JSON::Path::Tokenizer; $JSON::Path::Tokenizer::VERSION = '1.0.6'; use strict; use warnings; use Carp; use Readonly; use JSON::Path::Constants qw(:symbols :operators); use Exporter::Shiny 'tokenize'; Readonly my $ESCAPE_CHAR => qq{\\}; Readonly my %OPERATORS => ( $TOKEN_ROOT => 1, # $ $TOKEN_RECURSIVE => 1, # .. $TOKEN_CHILD => 1, # . $TOKEN_FILTER_OPEN => 1, # [?( $TOKEN_FILTER_SCRIPT_CLOSE => 1, # )] $TOKEN_SCRIPT_OPEN => 1, # [( $TOKEN_SUBSCRIPT_OPEN => 1, # [ $TOKEN_SUBSCRIPT_CLOSE => 1, # ] $TOKEN_QUOTE => 1, # " ); # my $invocation = 0; # ABSTRACT: Helper class for JSON::Path::Evaluator. Do not call directly. # Take an expression and break it up into tokens sub tokenize { my $expression = shift; #print "Tokenize \"$expression\"\n"; my $chars = [ split //, $expression ]; my @tokens; while ( defined( my $token = _read_to_next_token($chars) ) ) { # print "$invocation: Got token: $token\n"; push @tokens, $token; if ( $token eq $TOKEN_SCRIPT_OPEN || $token eq $TOKEN_FILTER_OPEN ) { # print "$invocation: script/filter open: $token\n"; push @tokens, _read_to_filter_script_close($chars); } } return @tokens; } sub _read_to_filter_script_close { my $chars = shift; my %escaped_chars = ( "b" => "\x{0008}", "f" => "\x{000C}", "n" => "\x{000A}", "r" => "\x{000D}", "t" => "\x{0009}", "v" => "\x{000B}", "0" => "\x{0000}", "'" => "\x{0027}", '"' => "\x{0022}", "\\" => "\x{005C}", ); #print "$invocation: read to filter script close: " . join( '', @{$chars} ) . "\n"; my $filter; my $in_regex; my $in_quote; my $escape = 0; my @quote_chars = ($APOSTROPHE, $QUOTATION_MARK); my @regex_chars = "/"; while ( defined( my $char = shift @{$chars} ) ) { if ( $in_quote ) { if ( $escape ) { ## Replace \t by tab, \\ by \, etc $char = $escaped_chars{$char} || $char; $escape = 0; } elsif ( $char eq "\\" ) { ## Don't include \ and flag so next char in sequence ## is replaced correctly. $escape = 1; next; } elsif ( $char eq $in_quote ) { $in_quote = ''; } } elsif ( $in_regex ) { if ( $escape ) { $escape = 0; } elsif ( $char eq "\\" ) { $escape = 1; } elsif ( $char eq $in_regex ) { $in_regex = ''; } } elsif (grep { $_ eq $char } @quote_chars) { $in_quote = $char; } elsif (grep { $_ eq $char } @regex_chars) { $in_regex = $char; } $filter .= $char; last unless @{$chars}; last if $chars->[0] eq $RIGHT_PARENTHESIS && !$in_quote && !$in_regex; } return $filter; } sub _read_to_next_token { #$invocation++; my $chars = shift; #print "$invocation: Get next token: " . join( '', @{$chars} ) . "\n"; my $in_quote = ''; my $token; while ( defined( my $char = shift @{$chars} ) ) { if ( $char eq $APOSTROPHE || $char eq $QUOTATION_MARK ) { #print "$invocation: Char is $APOSTROPHE or $QUOTATION_MARK. Char: $char, in_quote: $in_quote\n"; if ( $in_quote && $in_quote eq $char ) { $in_quote = ''; last; } $in_quote = $char; #print "$invocation: Set \$in_quote to $in_quote\n"; next; } if ( $char eq $ESCAPE_CHAR && !$in_quote ) { #print "$invocation: Got escape char: $char\n"; $token .= shift @{$chars}; next; } #print "Append '$char' to token '$token'\n"; $token .= $char; next if $in_quote; # Break out of the loop if the current character is the last one in the stream. last unless @{$chars}; if ( $char eq $LEFT_SQUARE_BRACKET ) { # distinguish between '[', '[(', and '[?(' if ( $chars->[0] eq $LEFT_PARENTHESIS ) { next; } if ( $chars->[0] eq $QUESTION_MARK ) { # The below appends the '?'. The '(' will be appended in the next iteration of the loop $token .= shift @{$chars}; next; } } elsif ( $char eq $RIGHT_PARENTHESIS ) { #print "$invocation: Found right parenthesis\n"; # A right parenthesis should be followed by a right square bracket, which itself is a token. # Append the next character and proceed. $token .= shift @{$chars}; #print "$invocation: Token is now: $token\n"; } elsif ( $char eq $FULL_STOP ) { # A full stop (i.e. a period, '.') may be the child operator '.' or the recursive operator '..' $token .= shift @{$chars} if $chars->[0] eq $FULL_STOP; } # If we've assembled an operator, we're done. last if $OPERATORS{$token}; # Similarly, if the next character is an operator, we're done last if $OPERATORS{ $chars->[0] }; } no warnings qw/uninitialized/; #print "$invocation: Token: $token\n"; use warnings qw/uninitialized/; return $token; } 1; __END__ =pod =encoding UTF-8 =head1 NAME JSON::Path::Tokenizer - Helper class for JSON::Path::Evaluator. Do not call directly. =head1 VERSION version 1.0.6 =head1 AUTHOR Aurelia Peters =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2024 by Aurelia Peters. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Constants.pm100644001750001750 772614612756433 17131 0ustar00tooktook000000000000JSON-Path-1.0.6/lib/JSON/Pathpackage JSON::Path::Constants; $JSON::Path::Constants::VERSION = '1.0.6'; use strict; use warnings; # ABSTRACT: Constants used in the JSON::Path distribution # VERSION use Readonly; use Exporter::Shiny; our %EXPORT_TAGS = ( symbols => [ '$DOLLAR_SIGN', '$COMMERCIAL_AT', '$FULL_STOP', '$LEFT_SQUARE_BRACKET', '$RIGHT_SQUARE_BRACKET', '$ASTERISK', '$COLON', '$LEFT_PARENTHESIS', '$RIGHT_PARENTHESIS', '$COMMA', '$QUESTION_MARK', '$EQUAL_SIGN', '$EXCLAMATION_MARK', '$GREATER_THAN_SIGN', '$LESS_THAN_SIGN', '$QUOTATION_MARK', '$APOSTROPHE', '$TILDE_SIGN' ], operators => [ '$TOKEN_ROOT', '$TOKEN_CURRENT', '$TOKEN_CHILD', '$TOKEN_RECURSIVE', '$TOKEN_ALL', '$TOKEN_FILTER_OPEN', '$TOKEN_SCRIPT_OPEN', '$TOKEN_FILTER_SCRIPT_CLOSE', '$TOKEN_SUBSCRIPT_OPEN', '$TOKEN_SUBSCRIPT_CLOSE', '$TOKEN_UNION', '$TOKEN_ARRAY_SLICE', '$TOKEN_SINGLE_EQUAL', '$TOKEN_DOUBLE_EQUAL', '$TOKEN_TRIPLE_EQUAL', '$TOKEN_GREATER_THAN', '$TOKEN_LESS_THAN', '$TOKEN_NOT_EQUAL', '$TOKEN_GREATER_EQUAL', '$TOKEN_LESS_EQUAL', '$TOKEN_QUOTE', '$TOKEN_REGEX', ], ); our @EXPORT_OK = map @$_, values %EXPORT_TAGS; Readonly our $QUOTATION_MARK => q{"}; Readonly our $APOSTROPHE => q{'}; Readonly our $DOLLAR_SIGN => '$'; Readonly our $COMMERCIAL_AT => '@'; Readonly our $FULL_STOP => '.'; Readonly our $LEFT_SQUARE_BRACKET => '['; Readonly our $RIGHT_SQUARE_BRACKET => ']'; Readonly our $ASTERISK => '*'; Readonly our $COLON => ':'; Readonly our $LEFT_PARENTHESIS => '('; Readonly our $RIGHT_PARENTHESIS => ')'; Readonly our $COMMA => ','; Readonly our $QUESTION_MARK => '?'; Readonly our $EQUAL_SIGN => '='; Readonly our $EXCLAMATION_MARK => '!'; Readonly our $GREATER_THAN_SIGN => '>'; Readonly our $LESS_THAN_SIGN => '<'; Readonly our $TILDE_SIGN => '~'; Readonly our $TOKEN_ROOT => $DOLLAR_SIGN; Readonly our $TOKEN_CURRENT => $COMMERCIAL_AT; Readonly our $TOKEN_CHILD => $FULL_STOP; Readonly our $TOKEN_RECURSIVE => $FULL_STOP . $FULL_STOP; Readonly our $TOKEN_ALL => $ASTERISK; Readonly our $TOKEN_FILTER_OPEN => $LEFT_SQUARE_BRACKET . $QUESTION_MARK . $LEFT_PARENTHESIS; Readonly our $TOKEN_SCRIPT_OPEN => $LEFT_SQUARE_BRACKET . $LEFT_PARENTHESIS; Readonly our $TOKEN_FILTER_SCRIPT_CLOSE => $RIGHT_PARENTHESIS . $RIGHT_SQUARE_BRACKET; Readonly our $TOKEN_SUBSCRIPT_OPEN => $LEFT_SQUARE_BRACKET; Readonly our $TOKEN_SUBSCRIPT_CLOSE => $RIGHT_SQUARE_BRACKET; Readonly our $TOKEN_UNION => $COMMA; Readonly our $TOKEN_ARRAY_SLICE => $COLON; Readonly our $TOKEN_SINGLE_EQUAL => $EQUAL_SIGN; Readonly our $TOKEN_DOUBLE_EQUAL => $EQUAL_SIGN . $EQUAL_SIGN; Readonly our $TOKEN_TRIPLE_EQUAL => $EQUAL_SIGN . $EQUAL_SIGN . $EQUAL_SIGN; Readonly our $TOKEN_GREATER_THAN => $GREATER_THAN_SIGN; Readonly our $TOKEN_LESS_THAN => $LESS_THAN_SIGN; Readonly our $TOKEN_NOT_EQUAL => $EXCLAMATION_MARK . $EQUAL_SIGN; Readonly our $TOKEN_GREATER_EQUAL => $GREATER_THAN_SIGN . $EQUAL_SIGN; Readonly our $TOKEN_LESS_EQUAL => $LESS_THAN_SIGN . $EQUAL_SIGN; Readonly our $TOKEN_QUOTE => $QUOTATION_MARK; Readonly our $TOKEN_REGEX => $EQUAL_SIGN . $TILDE_SIGN; 1; __END__ =pod =encoding UTF-8 =head1 NAME JSON::Path::Constants - Constants used in the JSON::Path distribution =head1 VERSION version 1.0.6 =head1 AUTHOR Aurelia Peters =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2024 by Aurelia Peters. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Evaluator.pm100644001750001750 7265514612756433 17142 0ustar00tooktook000000000000JSON-Path-1.0.6/lib/JSON/Pathpackage JSON::Path::Evaluator; $JSON::Path::Evaluator::VERSION = '1.0.6'; use strict; use warnings; # ABSTRACT: A module that recursively evaluates JSONPath expressions with native support for Javascript-style filters use Carp; use Carp::Assert qw(assert); use JSON::MaybeXS; use JSON::Path::Constants qw(:operators :symbols); use JSON::Path::Tokenizer qw(tokenize); use List::Util qw/pairs uniq/; use Readonly; use Safe; use Scalar::Util qw/looks_like_number blessed refaddr/; use Storable qw/dclone/; use Try::Tiny; # VERSION use Exporter::Shiny qw/evaluate_jsonpath/; our $AUTHORITY = 'cpan:POPEFELIX'; Readonly my $OPERATOR_IS_TRUE => 'IS_TRUE'; Readonly my $OPERATOR_TYPE_PATH => 1; Readonly my $OPERATOR_TYPE_COMPARISON => 2; Readonly my %OPERATORS => ( $TOKEN_ROOT => $OPERATOR_TYPE_PATH, # $ $TOKEN_CURRENT => $OPERATOR_TYPE_PATH, # @ $TOKEN_CHILD => $OPERATOR_TYPE_PATH, # . OR [] $TOKEN_RECURSIVE => $OPERATOR_TYPE_PATH, # .. $TOKEN_ALL => $OPERATOR_TYPE_PATH, # * $TOKEN_FILTER_OPEN => $OPERATOR_TYPE_PATH, # ?( $TOKEN_SCRIPT_OPEN => $OPERATOR_TYPE_PATH, # ( $TOKEN_FILTER_SCRIPT_CLOSE => $OPERATOR_TYPE_PATH, # ) $TOKEN_SUBSCRIPT_OPEN => $OPERATOR_TYPE_PATH, # [ $TOKEN_SUBSCRIPT_CLOSE => $OPERATOR_TYPE_PATH, # ] $TOKEN_UNION => $OPERATOR_TYPE_PATH, # , $TOKEN_ARRAY_SLICE => $OPERATOR_TYPE_PATH, # [ start:end:step ] $TOKEN_SINGLE_EQUAL => $OPERATOR_TYPE_COMPARISON, # = $TOKEN_DOUBLE_EQUAL => $OPERATOR_TYPE_COMPARISON, # == $TOKEN_TRIPLE_EQUAL => $OPERATOR_TYPE_COMPARISON, # === $TOKEN_GREATER_THAN => $OPERATOR_TYPE_COMPARISON, # > $TOKEN_LESS_THAN => $OPERATOR_TYPE_COMPARISON, # < $TOKEN_NOT_EQUAL => $OPERATOR_TYPE_COMPARISON, # != $TOKEN_GREATER_EQUAL => $OPERATOR_TYPE_COMPARISON, # >= $TOKEN_LESS_EQUAL => $OPERATOR_TYPE_COMPARISON, # <= $TOKEN_REGEX => $OPERATOR_TYPE_COMPARISON, # =~ ); Readonly my $ASSERT_ENABLE => $ENV{ASSERT_ENABLE}; sub new { my $class = shift; my %args = ref $_[0] eq 'HASH' ? %{ $_[0] } : @_; my $self = {}; for my $key (qw/root expression/) { croak qq{Missing required argument '$key' in constructor} unless $args{$key}; $self->{$key} = $args{$key}; } $self->{want_ref} = $args{want_ref} || 0; $self->{_calling_context} = $args{_calling_context} || 0; my $script_engine = $args{script_engine} ? $args{script_engine} : $self->{expression} =~ /\$_/ ? 'perl' : undef; $self->{script_engine} = $script_engine || 'PseudoJS'; bless $self, $class; return $self; } sub evaluate_jsonpath { my ( $json_object, $expression, %args ) = @_; if ( !ref $json_object ) { try { $json_object = decode_json($json_object); } catch { croak qq{Unable to decode $json_object as JSON: $_}; } } my $want_ref = delete $args{want_ref} || 0; my $want_path = delete $args{want_path} || 0; my $self = __PACKAGE__->new( root => $json_object, expression => $expression, _calling_context => wantarray ? 'ARRAY' : 'SCALAR', %args ); return $self->evaluate( $expression, want_ref => $want_ref, want_path => $want_path ); } sub evaluate { my ( $self, $expression, %args ) = @_; my $json_object = $self->{root}; my $token_stream = [ tokenize($expression) ]; #use Data::Dumper qw/Dumper/; #print Dumper $token_stream; shift @{$token_stream} if $token_stream->[0] eq $TOKEN_ROOT; shift @{$token_stream} if $token_stream->[0] eq $TOKEN_CHILD; if ( $args{want_path} ) { my %reftable = $self->_reftable_walker($json_object); my @refs = $self->_evaluate( $json_object, dclone $token_stream, 1 ); my @paths; for my $ref (@refs) { my $refaddr = ref ${$ref} ? refaddr ${$ref} : refaddr $ref; push @paths, $reftable{$refaddr}; } return @paths; } my @ret = $self->_evaluate( $json_object, $token_stream, $args{want_ref} ); return @ret; } sub _reftable_walker { my ( $self, $json_object, $base_path ) = @_; $base_path //= '$'; $json_object //= $self->root; my @entries = ( refaddr $json_object => $base_path ); if ( _arraylike($json_object) ) { for ( 0 .. $#{$json_object} ) { my $path = sprintf q{%s['%d']}, $base_path, $_; if ( ref $json_object->[$_] ) { push @entries, $self->_reftable_walker( $json_object->[$_], $path ); } else { push @entries, refaddr \( $json_object->[$_] ) => $path; } } } elsif ( _hashlike($json_object) ) { for my $index ( keys %{$json_object} ) { my $path = sprintf q{%s['%s']}, $base_path, $index; if ( ref $json_object->{$index} ) { push @entries, $self->_reftable_walker( $json_object->{$index}, $path ); } else { push @entries, refaddr \( $json_object->{$index} ) => $path; } } } return @entries; } sub _evaluate { # This assumes that the token stream is syntactically valid my ( $self, $obj, $token_stream, $want_ref ) = @_; return unless ref $obj; $token_stream //= []; while ( defined( my $token = shift @{$token_stream} ) ) { next if $token eq $TOKEN_CURRENT; next if $token eq $TOKEN_CHILD; if ( $token eq $TOKEN_FILTER_OPEN ) { my $filter_expression = shift @{$token_stream}; my $closing_token = shift @{$token_stream}; assert( $closing_token eq $TOKEN_FILTER_SCRIPT_CLOSE, q{Closing token seen} ) if $ASSERT_ENABLE; # Find all indices matching the filter expression. This modifies $token_stream my @matching_indices = $self->_process_filter( $obj, $filter_expression ); if ( !@{$token_stream} ) { my @got = map { _get( $obj, $_ ) } @matching_indices; return $want_ref ? @got : map { ${$_} } @got; } else { return map { $self->_evaluate( _get( $obj, $_ ), dclone($token_stream), $want_ref ) } @matching_indices; } } elsif ( $token eq $TOKEN_RECURSIVE ) { # Sweet Jesus, Pooh, that's not honey! You're eating Sweet Jesus, Pooh, that's not honey! You're eating... my $index = shift @{$token_stream}; my @matched; if ( $index eq $TOKEN_FILTER_OPEN ) { my $filter_expression = shift @{$token_stream}; my $closing_token = shift @{$token_stream}; assert( $closing_token eq $TOKEN_FILTER_SCRIPT_CLOSE, q{Closing token seen} ) if $ASSERT_ENABLE; return $self->_filter_recursive( $obj, $filter_expression, $want_ref ); } @matched = _match_recursive( $obj, $index, $want_ref ); if ( !@{$token_stream} ) { return @matched; } return map { $self->_evaluate( $_, dclone($token_stream), $want_ref ) } @matched; } else { my $index; if ( $token eq $TOKEN_SUBSCRIPT_OPEN ) { $index = shift @{$token_stream}; my $closing_token = shift @{$token_stream}; assert $closing_token eq $TOKEN_SUBSCRIPT_CLOSE if $ASSERT_ENABLE; } else { $index = $token; } assert( !$OPERATORS{$index}, qq{"$index" is not an operator} ) if $index ne $TOKEN_ALL; assert( !ref $index, q{Index is a scalar} ) if $ASSERT_ENABLE; my (@got) = _get( $obj, $index, create_key => $want_ref ); # This always returns a ref if ( !@{$token_stream} ) { return $want_ref ? @got : map { ${$_} } @got; } else { return map { $self->_evaluate( ${$_}, dclone($token_stream), $want_ref ) } @got; } } } } sub _process_filter { my ( $self, $obj, $filter_expression ) = @_; my @matching_indices; if ( $self->{script_engine} eq 'PseudoJS' ) { @matching_indices = $self->_process_pseudo_js( $obj, $filter_expression ); } elsif ( $self->{script_engine} eq 'perl' ) { @matching_indices = $self->_process_perl( $obj, $filter_expression ); } else { croak qq{Unsupported script engine "$self->{script_engine}"}; } return @matching_indices; } # This _always_ has to return a ref so that when it's called from evaluate( ... , want_ref => 1) # So that we can return a ref into the object (e.g. for use as an lvalue), even when the path points # to a scalar (which will of course be copied). # # I.E.: for { foo => 'bar' }, we always want \( foo->{bar} ) so that # JSON::Path->new('$.foo')->value($obj) = 'baz' works like it oughtta. sub _get { my ( $object, $index, %args ) = @_; assert( _hashlike($object) || _arraylike($object), 'Object is a hashref or an arrayref' ) if $ASSERT_ENABLE; my $create_key = $args{create_key}; # When want_ref is passed to _evaluate(), it will return a reference to whatever was matched. # If what was matched is itself a ref (e.g. an arrayref), _evaluate() will return a ref of # type 'REF'. if ( ref $object eq 'REF' ) { $object = ${$object}; } if ( $index eq $TOKEN_ALL ) { if ( _hashlike($object) ) { return map { \($_) } values %{$object}; } else { return map { \($_) } @{$object}; } } else { my @indices; if ( $index =~ /$TOKEN_ARRAY_SLICE/ ) { my $length = _hashlike($object) ? scalar values %{$object} : scalar @{$object}; @indices = _slice( $index, $length ); } elsif ( $index =~ /$TOKEN_UNION/ ) { @indices = split /$TOKEN_UNION/, $index; } else { @indices = ($index); } if ( _hashlike($object) ) { if ($create_key) { return map { \( $object->{$_} ) } @indices; } else { my @ret; for my $index (@indices) { push @ret, \( $object->{$index} ) if exists $object->{$index}; } return @ret; } } else { my @numeric_indices = grep { looks_like_number($_) } @indices; if ($create_key) { return map { \( $object->[$_] ) } @numeric_indices; } else { my @ret; for my $index (@numeric_indices) { push @ret, \( $object->[$index] ) if exists $object->[$index]; } return @ret; } } } } sub _indices { my $object = shift; return _hashlike($object) ? keys %{$object} : _arraylike($object) ? ( 0 .. $#{$object} ) : (); } sub _hashlike { my $object = shift; return ( ref $object eq 'HASH' || ( blessed $object && $object->can('typeof') && $object->typeof eq 'HASH' ) ); } sub _arraylike { my $object = shift; return ( ref $object eq 'ARRAY' || ( blessed $object && $object->can('typeof') && $object->typeof eq 'ARRAY' ) ); } sub _get_token { my $token_stream = shift; my $token = shift @{$token_stream}; return unless defined $token; if ( $token eq $TOKEN_SUBSCRIPT_OPEN ) { my @substream; my $close_seen; while ( defined( my $token = shift @{$token_stream} ) ) { if ( $token eq $TOKEN_SUBSCRIPT_CLOSE ) { $close_seen = 1; last; } push @substream, $token; } assert($close_seen) if $ASSERT_ENABLE; if ( grep { $_ eq $TOKEN_ARRAY_SLICE } @substream ) { # There are five valid cases: # # n:m -> n:m:1 # n:m:s -> n:m:s # :m -> 0:m:1 # ::s -> 0:-1:s # n: -> n:-1:1 if ( $substream[0] eq $TOKEN_ARRAY_SLICE ) { unshift @substream, undef; } no warnings qw/uninitialized/; if ( $substream[2] eq $TOKEN_ARRAY_SLICE ) { @substream = ( @substream[ ( 0, 1 ) ], undef, @substream[ ( 2 .. $#substream ) ] ); } use warnings qw/uninitialized/; my ( $start, $end, $step ); $start = $substream[0] // 0; $end = $substream[2] // -1; $step = $substream[4] // 1; return { slice => [ $start, $end, $step ] }; } elsif ( grep { $_ eq $TOKEN_UNION } @substream ) { my @union = grep { $_ ne $TOKEN_UNION } @substream; return { union => \@union }; } return $substream[0]; } return $token; } # See http://wiki.ecmascript.org/doku.php?id=proposals:slice_syntax # # in particular, for the slice [n:m], m is *one greater* than the last index to slice. # This means that the slice [3:5] will return indices 3 and 4, but *not* 5. sub _slice { my ( $index, $length ) = @_; my ( $start, $end, $step ) = split /$TOKEN_ARRAY_SLICE/, $index, 3; if ( !defined($start) || $start eq '' ) { $start = 0; } if ( !defined($end) || $end eq '' ) { $end = -1; } if ( !defined($step) || $step eq '' ) { $step = 1; } $start = ( $length - 1 ) if $start == -1; $end = $length if $end == -1; my @indices; if ( $step < 0 ) { @indices = grep { %_ % -$step == 0 } reverse( $start .. ( $end - 1 ) ); } else { @indices = grep { $_ % $step == 0 } ( $start .. ( $end - 1 ) ); } return @indices; } sub _match_recursive { my ( $obj, $index, $want_ref ) = @_; my @match; # Fix for RT #122529. # # Consider the expression "$..foo..bar", evaluated with respect to the JSON "{"foo":{"bar":"baz"}}". # # The first term to be evaluated in the expression is "$..foo". If want_ref is passed to evaluate(), # this will return a REF reference. In that case we must first dereference it to get the object that # we will evaluate "..bar" with respect to. if ( ref $obj eq 'REF' ) { $obj = ${$obj}; } if ( _arraylike($obj) ) { if ( looks_like_number($index) && exists $obj->[$index] ) { push @match, $want_ref ? \( $obj->[$index] ) : $obj->[$index]; } for ( 0 .. $#{$obj} ) { next unless ref $obj->[$_]; push @match, _match_recursive( $obj->[$_], $index, $want_ref ); } } elsif ( _hashlike($obj) ) { if ( exists $obj->{$index} ) { push @match, $want_ref ? \( $obj->{$index} ) : $obj->{$index}; } for my $val ( values %{$obj} ) { next unless ref $val; push @match, _match_recursive( $val, $index, $want_ref ); } } return @match; } sub _filter_recursive { my ( $self, $obj, $expression, $want_ref ) = @_; my @ret; # Evaluate the filter expression for the current object my @matching_indices = $self->_process_filter( $obj, $expression ); for my $index (@matching_indices) { my ($got) = _get( $obj, $index ); push @ret, $want_ref ? $got : ${$got}; } # Evaluate the filter expression for any subordinate objects for my $index ( _indices($obj) ) { my ($got) = _get( $obj, $index ); $got = ${$got}; # _get will always return a reference. We want the value, so dereference it next unless ref $got; push @ret, $self->_filter_recursive( $got, $expression, $want_ref ); } return @ret; } sub _process_pseudo_js { my ( $self, $object, $expressions ) = @_; my @expressions_or = split /\Q||\E/, $expressions; my @matching_or; foreach my $expression (@expressions_or) { my @expressions_and = split /\Q&&\E/, $expression; my %matching_and; foreach my $expression (@expressions_and) { my ( $lhs, $operator, $rhs ) = _parse_psuedojs_expression($expression); $lhs =~ s/^\s+|\s+$//g; my (@token_stream) = tokenize($lhs); if ( _hashlike($object) ) { while (my ($k, $v) = each(%$object)) { my @got = $self->_evaluate( $v, [@token_stream] ); foreach my $got (@got) { $matching_and{$k}++ if _compare( $operator, $got, $rhs ); } } } elsif ( _arraylike($object) ) { my $idx = 0; for my $value ( @{$object} ) { my ($got) = $self->_evaluate( $value, [@token_stream] ); $matching_and{$idx}++ if _compare( $operator, $got, $rhs ); $idx++; } } } while (my ($idx, $val) = each(%matching_and)) { push @matching_or, $idx if ($val == @expressions_and); } } return sort(uniq(@matching_or)); } sub _parse_psuedojs_expression { my $expression = shift; my @parts; my ( $lhs, $operator, $rhs ); # The operator could be '=', '!=', '==', '===', '<=', '>=' or '=~' if ( $expression =~ /$EQUAL_SIGN/ ) { my $position = index( $expression, '=' ); if ( substr( $expression, $position + 1, 1 ) eq $EQUAL_SIGN ) { # could be '==' or '===' if ( substr( $expression, $position + 2, 1 ) eq $EQUAL_SIGN ) { # === $operator = $TOKEN_TRIPLE_EQUAL; } else { $operator = $TOKEN_DOUBLE_EQUAL; } } elsif ( substr( $expression, $position + 1, 1 ) eq $TILDE_SIGN ) { $operator = $TOKEN_REGEX; } else { my $preceding_char = substr( $expression, $position - 1, 1 ); if ( $preceding_char eq $GREATER_THAN_SIGN ) { $operator = $TOKEN_GREATER_EQUAL; } elsif ( $preceding_char eq $LESS_THAN_SIGN ) { $operator = $TOKEN_LESS_EQUAL; } elsif ( $preceding_char eq $EXCLAMATION_MARK ) { $operator = $TOKEN_NOT_EQUAL; } else { $operator = $TOKEN_SINGLE_EQUAL; } } ( $lhs, $rhs ) = split /$operator/, $expression, 2; } else { for ( grep { $OPERATORS{$_} eq $OPERATOR_TYPE_COMPARISON } keys %OPERATORS ) { next if /$EQUAL_SIGN/; if ( $expression =~ /$_/ ) { ( $lhs, $rhs ) = split /$_/, $expression, 2; $operator = $_; last; } } } # FIXME: RHS is assumed to be a single value. This isn't necessarily a safe assumption. if ($operator) { $rhs = _normalize( $rhs || '' ); $lhs = _normalize($lhs); } else { $operator = $OPERATOR_IS_TRUE; $lhs = $expression; } return ( $lhs, $operator, $rhs ); } sub _normalize { my $string = shift; # NB: Stripping spaces *before* stripping quotes allows the caller to quote spaces in an index. # So an index of 'foo ' will be correctly normalized as 'foo', but '"foo "' will normalize to 'foo '. $string =~ s/\s+$//; # trim trailing spaces $string =~ s/^\s+//; # trim leading spaces $string =~ s/^['"](.+)['"]$/$1/; # Strip quotes from index return $string; } sub _process_perl { my ( $self, $object, $code ) = @_; my $cpt = Safe->new; $cpt->permit_only( ':base_core', qw/padsv padav padhv padany rv2gv/ ); ${ $cpt->varglob('root') } = dclone( $self->{root} ); my @matching; if ( _hashlike($object) ) { for my $index ( keys %{$object} ) { local $_ = $object->{$index}; my $ret = $cpt->reval($code); croak qq{Error in filter: $@} if $@; push @matching, $index if $ret; } } else { for my $index ( 0 .. $#{$object} ) { local $_ = $object->[$index]; my $ret = $cpt->reval($code); croak qq{Error in filter: $@} if $@; push @matching, $index if $ret; } } return @matching; } sub _compare { my ( $operator, $lhs, $rhs ) = @_; no warnings qw/uninitialized/; if ( $operator eq $OPERATOR_IS_TRUE ) { return $lhs ? 1 : 0; } my $use_numeric = looks_like_number($lhs) && looks_like_number($rhs); if ( $operator eq '=' || $operator eq '==' || $operator eq '===' ) { return $use_numeric ? ( $lhs == $rhs ) : $lhs eq $rhs; } if ( $operator eq '<' ) { return $use_numeric ? ( $lhs < $rhs ) : $lhs lt $rhs; } if ( $operator eq '>' ) { return $use_numeric ? ( $lhs > $rhs ) : $lhs gt $rhs; } if ( $operator eq '<=' ) { return $use_numeric ? ( $lhs <= $rhs ) : $lhs le $rhs; } if ( $operator eq '>=' ) { return $use_numeric ? ( $lhs >= $rhs ) : $lhs ge $rhs; } if ( $operator eq '!=' || $operator eq '!==' ) { return $use_numeric ? ( $lhs != $rhs ) : $lhs ne $rhs; } if ( $operator eq '=~' ) { if ( $rhs =~ m@^/(.*)/([msian]*)$@ ) { my $regex = $1; my $modifiers = $2; return $lhs =~ qr/(?$modifiers)$regex/; } else { warn("Regexp need to be sorrounded by //. Allowed modifiers: msian"); return 1; } } use warnings qw/uninitialized/; } 1; __END__ =pod =encoding UTF-8 =head1 NAME JSON::Path::Evaluator - A module that recursively evaluates JSONPath expressions with native support for Javascript-style filters =head1 VERSION version 1.0.6 =head1 SYNOPSIS use JSON::MaybeXS qw/decode_json/; # Or whatever JSON thing you like. I won't judge. use JSON::Path::Evaluator qw/evaluate_jsonpath/; my $obj = decode_json(q( { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } } )); my @fiction = evaluate_jsonpath( $obj, q{$..book[?(@.category == "fiction")]}); # @fiction = ( # { category => "fiction", # author => "Evelyn Waugh", # title => "Sword of Honour", # price => 12.99 # }, # { category => "fiction", # author => "Herman Melville", # title => "Moby Dick", # isbn => "0-553-21311-3", # price => 8.99 # }, # { category => "fiction", # author => "J. R. R. Tolkien", # title => "The Lord of the Rings", # isbn => "0-395-19395-8", # price => 22.99 # } # ); =head1 METHODS =head2 new Constructor for the object-oriented interface to this module. Arguments may be specified in a hash or a hashref. Args: =over 4 =item root Required. JSONPath expressions will be evaluated with respect to this. Must be a hashref or an arrayref. =item expression JSONPath expression to evaluate =item want_ref Set this to true if you want a reference to the thing the JSONPath expression matches, rather than the value of said thing. Useful if you want to use this to modify hashrefs / arrayrefs in place. =item script_engine Defaults to "PseudoJS", which is my clever name for a subset of Javascript-B operators for Boolean expressions. See L. You may also specify "perl" here, in which case the filter will be treated as Perl code. See L. =back =head2 evaluate_jsonpath Evaluate a JSONPath expression on the given object. CLASS METHOD. Args: =over 4 =item $json_object JSON object for which the expression will be evaluated. If this is a scalar, it will be treated as a JSON string and parsed into the appropriate Perl data structure first. =item $expression JSONPath expression to evaluate on the object. =item %args Misc. arguments to this method. Currently the only supported argument is 'want_ref' - set this to true in order to return a reference to the matched portion of the object, rather than the value of that matched portion. =back =head2 evaluate Evaluate a JSONPath expression on the object passed to the constructor. OBJECT METHOD. Args: =over 4 =item $expression JSONPath expression to evaluate on the object. =item %args Misc. arguments to this method. Supported keys: =over 4 =item want_ref Set this to true in order to return a reference to the matched portion of the object, rather than the value of the matched portion. =item want_path Set this to true in order to return the canonical path(s) to the elements matching the expression. =back =back =head1 JSONPath This code implements the JSONPath specification at L. JSONPath is a tool, similar to XPath for XML, that allows one to construct queries to pick out parts of a JSON structure. =head2 JSONPath Expressions From the spec: "JSONPath expressions always refer to a JSON structure in the same way as XPath expression are used in combination with an XML document. Since a JSON structure is usually anonymous and doesn't necessarily have a "root member object" JSONPath assumes the abstract name $ assigned to the outer level object." Note that in JSONPath square brackets operate on the object or array addressed by the previous path fragment. Indices always start by 0. =head2 Operators =over 4 =item $ the root object/element =item @ the current object/element =item . or [] child operator =item .. recursive descent. JSONPath borrows this syntax from E4X. =item * wildcard. All objects/elements regardless their names. =item [] subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator. =item [,] Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set. =item [start:end:step] array slice operator borrowed from ES4. =item ?() applies a filter (script) expression. See L. =item () script expression, using the underlying script engine. Handled the same as "?()". =back =head2 Filtering Filters are the most powerful feature of JSONPath. They allow the caller to retrieve data conditionally, similar to Perl's C operator. Filters are specified using the '?(' token, terminated by ')'. Anything in between these two tokens is treated as a filter expression. Filter expressions must return a boolean value. =head3 Filtering with PseudoJS By default, this module uses a limited subset of Javascript expressions to evaluate filters. Using this script engine, specify the filter in the form " ", or "". This latter case will be evaluated as " is true". must be a valid JSONPath expression. must be a scalar value; comparison of two JSONPath expressions is not supported at this time. Example: Using the JSON in L above and the JSONPath expression C<$..book[?(@.category == "fiction")]>, the filter expression C<@.category == "fiction"> will match all values having a value of "fiction" for the key "category". Regular expressions are supported using the C<=~> operator, for example: C<$..book[?(@.category =~ /Fiction/i)]>. This is an extension of the L introduced by L. Other Jayway operators are not currently supported. =head2 Filtering with Perl When the script engine is set to "perl", filter Using the JSON in L above and the JSONPath expression C<$..book[?(@.category == "fiction")]>, This is understandably dangerous. Although steps have been taken (Perl expressions are evaluated using L and a limited set of permitted opcodes) to reduce the risk, callers should be aware of the risk when using filters. When filtering in Perl, there are some differences between the JSONPath spec and this implementation. =over 4 =item * JSONPath uses the token '$' to refer to the root node. As this is not valid Perl, this should be replaced with '$root' in a filter expression. =item * JSONPath uses the token '@' to refer to the current node. This is also not valid Perl. Use '$_' instead. =back =head1 AUTHOR Aurelia Peters =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2024 by Aurelia Peters. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut filter_expression_regex.t100644001750001750 602314612756433 17757 0ustar00tooktook000000000000JSON-Path-1.0.6/t=head1 PURPOSE Test expressions that use regexes within the filter part of the path. =cut use Test2::V0; use JSON::Path::Evaluator qw/evaluate_jsonpath/; my $json = q@{ "Competency" : [ { "level" : 75, "name" : "Marketing" }, { "level" : 100, "name" : "Market Analysis" }, { "level" : 500, "name" : "[Something] ('/Else/') \"\@-3/2\\\\8/\"" } ] }@; my @data; @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /Market/)]'); is(@data, 2, 'Regex work. /Market/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /market/)]'); is(@data, 0, 'Nothing found, wrong case. /market/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /market/i)]'); is(@data, 2, 'Regex with i modifier works. /market/i'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /^market$/)]'); is(@data, 0, 'Regex with ^ and $ works. /^market$/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /market/i && @.level > 80 )]'); is(@data, 1, 'Regex works combined with other clausules (and)'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level > 100 || @.name =~ /market/i)]'); is(@data, 3, 'Regex works combined with other clausules (or)'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /\[\w+\]/)]'); is(@data, 1, 'A bit more complex regex. /\[\w+\]/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /\w{9}|\w{15}/)]'); is(@data, 2, 'Another slightly complex regex. /\w{9}|\w{15}/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /\'\/Else\/\'/)]'); is(@data, 1, 'Can use \' and / inside regex. /\'\/Else\/\'/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /"\/Else\/"/)]'); is(@data, 0, 'Can use " and / inside regex. /"\/Else\/"/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /"@-\d\/\d\\\\.*"/)]'); is(@data, 1, 'Try more special characers inside regex. /"@-\d\/\d\\\\.*"/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /"-\d\/\d\\\\.*"/)]'); is(@data, 0, 'Similar but failing to match. /"-\d\/\d\\\\.*"/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /\] \(.*\'.*\/\d\\\\8\//)]'); is(@data, 1, 'More weird expression. /\] \(.*\'.*\/\d\\\\8\//'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /\(.*\)/)]'); is(@data, 1, 'Escaped parenthesis are parenthesis. /\(.*\)/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /(.*)/)]'); is(@data, 3, 'But not escaped parenthesis group stuff. /(.*)/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /^marketing|analysis$/i)]'); is(@data, 2, 'Simple expression not grouped. /^marketing|analysis$/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /^(marketing|analysis)$/i)]'); is(@data, 1, 'Simple expression now grouped. /^(marketing|analysis)$/'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name =~ /^(?:marketing|analysis)$/i)]'); is(@data, 1, '?: has no effect. /^(?:marketing|analysis)$/'); done_testing(); filter_expression_and_or.t100644001750001750 766214612756433 20121 0ustar00tooktook000000000000JSON-Path-1.0.6/t=head1 PURPOSE Test expressions that use AND (&&) and/or OR (||) within the filter part of the path. =cut use Test2::V0; use JSON::Path::Evaluator qw/evaluate_jsonpath/; my $json = q@{ "Competency" : [ { "level" : 75, "name" : "Marketing" }, { "level" : 500, "name" : "Something Else" } ] }@; my @data; ### AND test @data = evaluate_jsonpath($json, '$.Competency[?(@.level>=0 && @.level<25)].name'); is(@data, 0, 'Nothing between 0 and 25'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level<25 && @.level>=0)].name'); is(@data, 0, 'Nothing between 25 and 0'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>=0 && @.level<100)].name'); is(@data, 1, 'One value between 0 and 100'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level<100 && @.level>=0)].name'); is(@data, 1, 'One value between 100 and 0'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>=0 && @.level<1000)].name'); is(@data, 2, 'Two values between 0 and 1000'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level<1000 && @.level>=0)].name'); is(@data, 2, 'Two values between 1000 and 0'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>=0 && @.name=="Marketing" && @.level<100)].name'); is(@data, 1, 'Got Marketing'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>=0 && @.name=="Marketing" && @.level<50)].name'); is(@data, 0, 'No Marketing'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>=0 && @.name=="Marketong" && @.level<100)].name'); is(@data, 0, 'No Marketong'); ## OR test @data = evaluate_jsonpath($json, '$.Competency[?(@.level>0 || @.level>1000)].name'); is(@data, 2, 'All values are more than zero OR more than 1000'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>1000 || @.level>0)].name'); is(@data, 2, 'The other way around'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>1000 || @.level>500)].name'); is(@data, 0, 'No value greater than 1000 or 500'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>1000 || @.level>200)].name'); is(@data, 1, 'One value greater than 1000 or 200'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>1000 || @.level>200 || @.level>50)].name'); is(@data, 2, 'Two values greater than 1000 or 200 or 50'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level>1000 || @.level>200 || @.name=="Marketing")].name'); is(@data, 2, 'One value greater than 1000 or 200 and one Marketing'); ## Mix AND and OR @data = evaluate_jsonpath($json, '$.Competency[?(@.level==75 && @.name=="Marketing" || @.level==500 && @.name="Something Else")].name'); is(@data, 2, 'Got "Marketing" and "Something Else"'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level==500 && @.name=="Marketing" || @.level==75 && @.name="Something Else")].name'); is(@data, 0, 'Got Nothing'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name && @.level )]'); is(@data, 2, 'LHS Trimmed when necessary'); SKIP: { skip "Not working on AND/OR naive and quick implementation"; @data = evaluate_jsonpath($json, '$.Competency[?(@.level>1000 || @.level>200 || @.name!="Ben && Jerry")].name'); is(@data, 2, 'Data containing "&&" might break things'); @data = evaluate_jsonpath($json, '$.Competency[?(@.name!="Ben || Jerry" && @.level>1000)].name'); is(@data, 0, 'Data containing "||" might break things'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level==75 && ( @.name=="Marketing" || @.name="Something Else" ) && @.level==500)].name'); is(@data, 0, 'Brackets not working as expected'); @data = evaluate_jsonpath($json, '$.Competency[?(( @.name=="Marketing" || @.name="Something Else" ) && @.level==500)].name'); is(@data, 1, 'Brackets not working as expected'); @data = evaluate_jsonpath($json, '$.Competency[?(@.level==75 && ( @.name=="Marketing" || @.name="Something Else" ))].name'); is(@data, 1, 'Brackets not working as expected'); }; done_testing(); path-construction-failure.t100644001750001750 231514612756433 20132 0ustar00tooktook000000000000JSON-Path-1.0.6/tuse Test2::V0 '-target' => 'JSON::Path'; # Test demonstrating RT #122109, "paths method succeeds in search but then fails on path construction" # https://rt.cpan.org/Ticket/Display.html?id=122109 # my $json='{ "4" : { "value_raw" : "European", "value" : "European", "name" : "Ethnicity", "type" : "radio", "id" : 4 }, "1" : { "middle" : "", "first" : "James", "value" : "James Bowery", "last" : "Bowery", "name" : "Name", "type" : "name", "id" : 1 }, "3" : { "value_raw" : "Male", "value" : "Male", "name" : "Gender", "type" : "radio", "id" : 3 }, "2" : { "unix" : 1498176000, "time" : "", "date" : "06/23/2017", "value" : "06/23/2017", "name" : "Birthdate", "type" : "date-time", "id" : 2 }, "5" : { "value" : "jabowery@emailservice.com", "name" : "Email", "type" : "text", "id" : 5 } }'; my $p3 = $CLASS->new( '$.[?($_->{name} eq "Email")]'); my @paths; ok lives { @paths = $p3->paths($json) }, q{paths() did not die} or diag qq{Caught exception: $@}; is \@paths, [ q{$['5']} ], q{paths() produced correct path}; done_testing; quotes-in-filter-expression.t100644001750001750 162514612756433 20430 0ustar00tooktook000000000000JSON-Path-1.0.6/tuse Test2::V0 '-target' => 'JSON::Path'; local $JSON::Path::Safe = 0; # use strict; # use JSON::Path; # use diagnostics; my $json = q|{ "phones": [ { "type" : "iPhone", "number": "(123rpar 456-7890" }, { "type" : "home", "number": "(123) 456-7890" }, { "type" : "''\"']w[(o)\\r{k}'\"''", "number": "987 654 321" } ] }|; use Data::Dumper; warn(Dumper($json)); my $phone_number; $phone_number = '(123) 456-7890'; # $phone_number = '(123rpar 456-7890'; # <-- works, the above does not my $jpath = JSON::Path->new('$.phones.[?($_->{number} eq "(123) 456-7890")].type'); my @types = $jpath->values($json); is($types[0], "home", "Got the right type"); local $JSON::Path::Safe = 1; $jpath = JSON::Path->new(q|$.phones[?(@.type == "''\"']w[(o)\\r{k}'\"''")]|); @types = $jpath->paths($json); is($types[0], q|$['phones']['2']|, "Got the right type with insane quotes all around"); done_testing(); filter_expression_nested_objects.t100644001750001750 671314612756433 21646 0ustar00tooktook000000000000JSON-Path-1.0.6/t=head1 PURPOSE Test filter expressions with nested objects/hashrefs. =cut use Test2::V0; use JSON::Path::Evaluator qw/evaluate_jsonpath/; my $json = q@{ "Competency" : [ { "C1": { "level" : 75, "name" : "Marketing" }, "C2": { "level" : 500, "name" : "Something Else" } }, { "C1": { "level" : 60, "name" : "Perl", "absurdily": { "nested": { "data": { "structure": { "arrays_here": [ [[1]], [[2]], [[3],[ { "goal": "coins" }]] ] } } } } }, "C2": { "level" : 100, "name" : "JavaScript" }, "C3": { "name" : "Python", "absurdily": { "nested": { "data": { "structure": { "arrays_here": [ [[1]], [[2]], [[3],[ { "goal": "treasure" }]] ] } } } } } } ] }@; my @data; @data = evaluate_jsonpath($json, '$.Competency[*][*]'); is(@data, 5, 'Everything found using [*][*]'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.name=="Marketing")].name'); ok(@data == 1 && $data[0] eq 'Marketing', 'Marketing found using [*][?(@.name=="Marketing")] filter'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.name=="JavaScript")].name'); ok(@data == 1 && $data[0] eq 'JavaScript', 'JavaScript found using filter [*][?(@.name=="JavaScript")]'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.name=="JavaScript" && @.level > 50)].name'); ok(@data == 1 && $data[0] eq 'JavaScript', 'JavaScript found adding @.level > 50) condition'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.name=="JavaScript" && @.level < 50)]'); is(@data, 0, 'JavaScript not found with condition @.level > 50'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.name=="Java")]'); is(@data, 0, 'Java not found with filter [*][?(@.name=="Java")]'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.level >= 75)]'); is(@data, 3, 'Everything with level >= 75 found'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.level < 75)]'); is(@data, 1, 'Everything with level < 75 found'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.name=="Python")].absurdily.nested.data.structure.arrays_here[2][1][0].goal'); ok(@data == 1 && $data[0] eq 'treasure', 'Found absurdily nested data filtering by Python'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.absurdily.nested.data.structure.arrays_here[2][1][0].goal=="treasure")].name'); ok(@data == 1 && $data[0] eq 'Python', 'Found Python filtering with absurdily nested data'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.absurdily.nested.data.structure.arrays_here[2][1][0].goal)].name'); is(@data, 2, 'Found Python and Perl filtering with absurdily nested data'); @data = evaluate_jsonpath($json, '$.Competency[*][?(@.absurdily.nested.data.structure.arrays_here[2][1][0].goal && @.level > 55)].name'); ok(@data == 1 && $data[0] eq 'Perl', 'Found Perl filtering with absurdily nested data'); done_testing(); path-construction-fail.t100644001750001750 247314612756433 21425 0ustar00tooktook000000000000JSON-Path-1.0.6/t/evaluatoruse Test2::V0 '-target' => 'JSON::Path'; use JSON::MaybeXS qw/decode_json/; # Test demonstrating RT #122109, "paths method succeeds in search but then fails on path construction" # https://rt.cpan.org/Ticket/Display.html?id=122109 # local $JSON::Path::Safe = 0; my $json = '{ "4" : { "value_raw" : "European", "value" : "European", "name" : "Ethnicity", "type" : "radio", "id" : 4 }, "1" : { "middle" : "", "first" : "James", "value" : "James Bowery", "last" : "Bowery", "name" : "Name", "type" : "name", "id" : 1 }, "3" : { "value_raw" : "Male", "value" : "Male", "name" : "Gender", "type" : "radio", "id" : 3 }, "2" : { "unix" : 1498176000, "time" : "", "date" : "06/23/2017", "value" : "06/23/2017", "name" : "Birthdate", "type" : "date-time", "id" : 2 }, "5" : { "value" : "jabowery@emailservice.com", "name" : "Email", "type" : "text", "id" : 5 } }'; my $json_hash = decode_json($json); my $p3 = $CLASS->new('$.[?($_->{name} eq "Email")]'); my @paths; ok lives { @paths = $p3->paths($json_hash) }, q{paths() did not die} or diag qq{Caught exception: $@}; is \@paths, [q{$['5']}], q{paths() produced correct path}; done_testing; jsonpath-compliance-test-suite000755001750001750 014612756433 20272 5ustar00tooktook000000000000JSON-Path-1.0.6NOTICE100644001750001750 70314612756433 21316 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suitejsonpath-compliance-test-suite Copyright 2020 VMware, Inc. This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 License. This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. LICENSE100644001750001750 270614612756433 21444 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suitejsonpath-compliance-test-suite The BSD-2 license (the "License") set forth below applies to all parts of the jsonpath-compliance-test-suite project. You may not use this file except in compliance with the License. BSD-2 License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. build.js100644001750001750 746714612756433 22105 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite// @ts-check const fs = require('fs'); const path = require('path'); /** * The file extension of test files. * @type {string} */ const fileExtension = '.json'; /** * The number of spaces to use for indentation in the output. * @type {number} */ const jsonIndent = 2; /** * The separator to use when combining test names. * @type {string} */ const testNameSeparator = ', '; /** * The description of the test suite. * @type {string} */ const description = 'JSONPath Compliance Test Suite. This file is autogenerated, do not edit.'; build(); /** * Build a combined test suite from a directory of test files. * The output is written to stdout. */ function build() { if (process.argv.length < 3) { console.error('Usage: node build.js '); process.exit(1); } const testsFolder = process.argv[2]; const tests = readTestsFromDir(testsFolder); const cts = {'description': description, 'tests': tests}; console.log(JSON.stringify(cts, null, jsonIndent)); console.error(`Wrote ${tests.length} tests to stdout.`); } /** * Read all test files from a directory and its subdirectories. * The directory name is prepended to the test name. * @param dir {string} - The directory to read. * @param relativePath {string[]} - The path to the directory. * @returns {*[]} - An array of test objects. */ function readTestsFromDir(dir, relativePath = []) { const files = fs.readdirSync(dir); files.sort(filesBeforeDirs); return files.reduce(addTestsFromFile, []); /** * Add tests from a file to the list of all tests. * @param allTests - The list of all tests. * @param file - The file to read. * @returns {*} - The updated list of all tests. */ function addTestsFromFile(allTests, file) { const fullPath = path.join(dir, file); if (isDir(file)) { console.error(`Processing dir ${fullPath}`); const tests = readTestsFromDir(fullPath, [...relativePath, file]); return allTests.concat(tests); } if (path.extname(file) === fileExtension) { console.error(`Processing file ${fullPath}`); const basename = path.basename(file, fileExtension); const testNamePrefix = [...relativePath, basename] .join(testNameSeparator) .replace('_', ' '); const tests = readTestsFromFile(fullPath).map(prependToTestName(testNamePrefix)); return allTests.concat(tests); } return allTests; } /** * Sort entries so that directories are listed after files. * @param first - The first file. * @param second - The second file. * @returns {number} */ function filesBeforeDirs(first, second) { const firstIsDir = isDir(first); const secondIsDir = isDir(second); if (firstIsDir && !secondIsDir) return 1; if (!firstIsDir && secondIsDir) return -1; return first.localeCompare(second, 'en', {sensitivity: 'base'}); } /** * Check if a file is a directory. * @param file {string} - The file name. * @returns {boolean} - True if the file is a directory. */ function isDir(file) { return fs.statSync(path.join(dir, file)).isDirectory(); } } /** * Read the tests from a file. * @param file - The file to read. * @returns {*[]} */ function readTestsFromFile(file) { const fileData = fs.readFileSync(file, 'utf8'); return JSON.parse(fileData).tests; } /** * Prepend the prefix to the test name. * @param prefix {string} - The file name. * @returns {function(*): *&{name: string}} - A function that prepends the file name to the test name. */ function prependToTestName(prefix) { return (test) => { return { ...test, name: prefix + testNameSeparator + test.name, }; }; } cts.json100644001750001750 43502514612756433 22167 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite{ "description": "JSONPath Compliance Test Suite. This file is autogenerated, do not edit.", "tests": [ { "name": "basic, root", "selector": "$", "document": [ "first", "second" ], "result": [ [ "first", "second" ] ] }, { "name": "basic, no leading whitespace", "selector": " $", "invalid_selector": true }, { "name": "basic, no trailing whitespace", "selector": "$ ", "invalid_selector": true }, { "name": "basic, name shorthand", "selector": "$.a", "document": { "a": "A", "b": "B" }, "result": [ "A" ] }, { "name": "basic, name shorthand, extended unicode ☺", "selector": "$.☺", "document": { "☺": "A", "b": "B" }, "result": [ "A" ] }, { "name": "basic, name shorthand, underscore", "selector": "$._", "document": { "_": "A", "_foo": "B" }, "result": [ "A" ] }, { "name": "basic, name shorthand, symbol", "selector": "$.&", "invalid_selector": true }, { "name": "basic, name shorthand, number", "selector": "$.1", "invalid_selector": true }, { "name": "basic, name shorthand, absent data", "selector": "$.c", "document": { "a": "A", "b": "B" }, "result": [] }, { "name": "basic, name shorthand, array data", "selector": "$.a", "document": [ "first", "second" ], "result": [] }, { "name": "basic, wildcard shorthand, object data", "selector": "$.*", "document": { "a": "A", "b": "B" }, "results": [ [ "A", "B" ], [ "B", "A" ] ] }, { "name": "basic, wildcard shorthand, array data", "selector": "$.*", "document": [ "first", "second" ], "result": [ "first", "second" ] }, { "name": "basic, wildcard selector, array data", "selector": "$[*]", "document": [ "first", "second" ], "result": [ "first", "second" ] }, { "name": "basic, wildcard shorthand, then name shorthand", "selector": "$.*.a", "document": { "x": { "a": "Ax", "b": "Bx" }, "y": { "a": "Ay", "b": "By" } }, "results": [ [ "Ax", "Ay" ], [ "Ay", "Ax" ] ] }, { "name": "basic, multiple selectors", "selector": "$[0,2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 2 ] }, { "name": "basic, multiple selectors, space instead of comma", "selector": "$[0 2]", "invalid_selector": true }, { "name": "basic, multiple selectors, name and index, array data", "selector": "$['a',1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1 ] }, { "name": "basic, multiple selectors, name and index, object data", "selector": "$['a',1]", "document": { "a": 1, "b": 2 }, "result": [ 1 ] }, { "name": "basic, multiple selectors, index and slice", "selector": "$[1,5:7]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 5, 6 ] }, { "name": "basic, multiple selectors, index and slice, overlapping", "selector": "$[1,0:3]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 0, 1, 2 ] }, { "name": "basic, multiple selectors, duplicate index", "selector": "$[1,1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 1 ] }, { "name": "basic, multiple selectors, wildcard and index", "selector": "$[*,1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1 ] }, { "name": "basic, multiple selectors, wildcard and name", "selector": "$[*,'a']", "document": { "a": "A", "b": "B" }, "results": [ [ "A", "B", "A" ], [ "B", "A", "A" ] ] }, { "name": "basic, multiple selectors, wildcard and slice", "selector": "$[*,0:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 ] }, { "name": "basic, multiple selectors, multiple wildcards", "selector": "$[*,*]", "document": [ 0, 1, 2 ], "result": [ 0, 1, 2, 0, 1, 2 ] }, { "name": "basic, empty segment", "selector": "$[]", "invalid_selector": true }, { "name": "basic, descendant segment, index", "selector": "$..[1]", "document": { "o": [ 0, 1, [ 2, 3 ] ] }, "result": [ 1, 3 ] }, { "name": "basic, descendant segment, name shorthand", "selector": "$..a", "document": { "o": [ { "a": "b" }, { "a": "c" } ] }, "result": [ "b", "c" ] }, { "name": "basic, descendant segment, wildcard shorthand, array data", "selector": "$..*", "document": [ 0, 1 ], "result": [ 0, 1 ] }, { "name": "basic, descendant segment, wildcard selector, array data", "selector": "$..[*]", "document": [ 0, 1 ], "result": [ 0, 1 ] }, { "name": "basic, descendant segment, wildcard selector, nested arrays", "selector": "$..[*]", "document": [ [ [ 1 ] ], [ 2 ] ], "results": [ [ [ [ 1 ] ], [ 2 ], [ 1 ], 1, 2 ], [ [ [ 1 ] ], [ 2 ], [ 1 ], 2, 1 ] ] }, { "name": "basic, descendant segment, wildcard selector, nested objects", "selector": "$..[*]", "document": { "a": { "c": { "e": 1 } }, "b": { "d": 2 } }, "results": [ [ { "c": { "e": 1 } }, { "d": 2 }, { "e": 1 }, 1, 2 ], [ { "c": { "e": 1 } }, { "d": 2 }, { "e": 1 }, 2, 1 ], [ { "c": { "e": 1 } }, { "d": 2 }, 2, { "e": 1 }, 1 ], [ { "d": 2 }, { "c": { "e": 1 } }, { "e": 1 }, 1, 2 ], [ { "d": 2 }, { "c": { "e": 1 } }, { "e": 1 }, 2, 1 ], [ { "d": 2 }, { "c": { "e": 1 } }, 2, { "e": 1 }, 1 ] ] }, { "name": "basic, descendant segment, wildcard shorthand, object data", "selector": "$..*", "document": { "a": "b" }, "result": [ "b" ] }, { "name": "basic, descendant segment, wildcard shorthand, nested data", "selector": "$..*", "document": { "o": [ { "a": "b" } ] }, "result": [ [ { "a": "b" } ], { "a": "b" }, "b" ] }, { "name": "basic, descendant segment, multiple selectors", "selector": "$..['a','d']", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" } ], "result": [ "b", "e", "c", "f" ] }, { "name": "basic, descendant segment, object traversal, multiple selectors", "selector": "$..['a','d']", "document": { "x": { "a": "b", "d": "e" }, "y": { "a": "c", "d": "f" } }, "results": [ [ "b", "e", "c", "f" ], [ "c", "f", "b", "e" ] ] }, { "name": "basic, bald descendant segment", "selector": "$..", "invalid_selector": true }, { "name": "filter, existence, without segments", "selector": "$[?@]", "document": { "a": 1, "b": null }, "results": [ [ 1, null ], [ null, 1 ] ] }, { "name": "filter, existence", "selector": "$[?@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "filter, existence, present with null", "selector": "$[?@.a]", "document": [ { "a": null, "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": null, "d": "e" } ] }, { "name": "filter, equals string, single quotes", "selector": "$[?@.a=='b']", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "filter, equals numeric string, single quotes", "selector": "$[?@.a=='1']", "document": [ { "a": "1", "d": "e" }, { "a": 1, "d": "f" } ], "result": [ { "a": "1", "d": "e" } ] }, { "name": "filter, equals string, double quotes", "selector": "$[?@.a==\"b\"]", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "filter, equals numeric string, double quotes", "selector": "$[?@.a==\"1\"]", "document": [ { "a": "1", "d": "e" }, { "a": 1, "d": "f" } ], "result": [ { "a": "1", "d": "e" } ] }, { "name": "filter, equals number", "selector": "$[?@.a==1]", "document": [ { "a": 1, "d": "e" }, { "a": "c", "d": "f" }, { "a": 2, "d": "f" }, { "a": "1", "d": "f" } ], "result": [ { "a": 1, "d": "e" } ] }, { "name": "filter, equals null", "selector": "$[?@.a==null]", "document": [ { "a": null, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": null, "d": "e" } ] }, { "name": "filter, equals null, absent from data", "selector": "$[?@.a==null]", "document": [ { "d": "e" }, { "a": "c", "d": "f" } ], "result": [] }, { "name": "filter, equals true", "selector": "$[?@.a==true]", "document": [ { "a": true, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": true, "d": "e" } ] }, { "name": "filter, equals false", "selector": "$[?@.a==false]", "document": [ { "a": false, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": false, "d": "e" } ] }, { "name": "filter, equals self", "selector": "$[?@==@]", "document": [ 1, null, true, { "a": "b" }, [ false ] ], "result": [ 1, null, true, { "a": "b" }, [ false ] ] }, { "name": "filter, deep equality, arrays", "selector": "$[?@.a==@.b]", "document": [ { "a": false, "b": [ 1, 2 ] }, { "a": [ [ 1, [ 2 ] ] ], "b": [ [ 1, [ 2 ] ] ] }, { "a": [ [ 1, [ 2 ] ] ], "b": [ [ [ 2 ], 1 ] ] }, { "a": [ [ 1, [ 2 ] ] ], "b": [ [ 1, 2 ] ] } ], "result": [ { "a": [ [ 1, [ 2 ] ] ], "b": [ [ 1, [ 2 ] ] ] } ] }, { "name": "filter, deep equality, objects", "selector": "$[?@.a==@.b]", "document": [ { "a": false, "b": { "x": 1, "y": { "z": 1 } } }, { "a": { "x": 1, "y": { "z": 1 } }, "b": { "x": 1, "y": { "z": 1 } } }, { "a": { "x": 1, "y": { "z": 1 } }, "b": { "y": { "z": 1 }, "x": 1 } }, { "a": { "x": 1, "y": { "z": 1 } }, "b": { "x": 1 } }, { "a": { "x": 1, "y": { "z": 1 } }, "b": { "x": 1, "y": { "z": 2 } } } ], "result": [ { "a": { "x": 1, "y": { "z": 1 } }, "b": { "x": 1, "y": { "z": 1 } } }, { "a": { "x": 1, "y": { "z": 1 } }, "b": { "y": { "z": 1 }, "x": 1 } } ] }, { "name": "filter, not-equals string, single quotes", "selector": "$[?@.a!='b']", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "c", "d": "f" } ] }, { "name": "filter, not-equals numeric string, single quotes", "selector": "$[?@.a!='1']", "document": [ { "a": "1", "d": "e" }, { "a": 1, "d": "f" } ], "result": [ { "a": 1, "d": "f" } ] }, { "name": "filter, not-equals string, single quotes, different type", "selector": "$[?@.a!='b']", "document": [ { "a": "b", "d": "e" }, { "a": 1, "d": "f" } ], "result": [ { "a": 1, "d": "f" } ] }, { "name": "filter, not-equals string, double quotes", "selector": "$[?@.a!=\"b\"]", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "c", "d": "f" } ] }, { "name": "filter, not-equals numeric string, double quotes", "selector": "$[?@.a!=\"1\"]", "document": [ { "a": "1", "d": "e" }, { "a": 1, "d": "f" } ], "result": [ { "a": 1, "d": "f" } ] }, { "name": "filter, not-equals string, double quotes, different types", "selector": "$[?@.a!=\"b\"]", "document": [ { "a": "b", "d": "e" }, { "a": 1, "d": "f" } ], "result": [ { "a": 1, "d": "f" } ] }, { "name": "filter, not-equals number", "selector": "$[?@.a!=1]", "document": [ { "a": 1, "d": "e" }, { "a": 2, "d": "f" }, { "a": "1", "d": "f" } ], "result": [ { "a": 2, "d": "f" }, { "a": "1", "d": "f" } ] }, { "name": "filter, not-equals number, different types", "selector": "$[?@.a!=1]", "document": [ { "a": 1, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "c", "d": "f" } ] }, { "name": "filter, not-equals null", "selector": "$[?@.a!=null]", "document": [ { "a": null, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "c", "d": "f" } ] }, { "name": "filter, not-equals null, absent from data", "selector": "$[?@.a!=null]", "document": [ { "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "d": "e" }, { "a": "c", "d": "f" } ] }, { "name": "filter, not-equals true", "selector": "$[?@.a!=true]", "document": [ { "a": true, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "c", "d": "f" } ] }, { "name": "filter, not-equals false", "selector": "$[?@.a!=false]", "document": [ { "a": false, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "c", "d": "f" } ] }, { "name": "filter, less than string, single quotes", "selector": "$[?@.a<'c']", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "filter, less than string, double quotes", "selector": "$[?@.a<\"c\"]", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "filter, less than number", "selector": "$[?@.a<10]", "document": [ { "a": 1, "d": "e" }, { "a": 10, "d": "e" }, { "a": "c", "d": "f" }, { "a": 20, "d": "f" } ], "result": [ { "a": 1, "d": "e" } ] }, { "name": "filter, less than null", "selector": "$[?@.a'c']", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "d", "d": "f" } ] }, { "name": "filter, greater than string, double quotes", "selector": "$[?@.a>\"c\"]", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "d", "d": "f" } ] }, { "name": "filter, greater than number", "selector": "$[?@.a>10]", "document": [ { "a": 1, "d": "e" }, { "a": 10, "d": "e" }, { "a": "c", "d": "f" }, { "a": 20, "d": "f" } ], "result": [ { "a": 20, "d": "f" } ] }, { "name": "filter, greater than null", "selector": "$[?@.a>null]", "document": [ { "a": null, "d": "e" }, { "a": "c", "d": "f" } ], "result": [] }, { "name": "filter, greater than true", "selector": "$[?@.a>true]", "document": [ { "a": true, "d": "e" }, { "a": "c", "d": "f" } ], "result": [] }, { "name": "filter, greater than false", "selector": "$[?@.a>false]", "document": [ { "a": false, "d": "e" }, { "a": "c", "d": "f" } ], "result": [] }, { "name": "filter, greater than or equal to string, single quotes", "selector": "$[?@.a>='c']", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "c", "d": "f" }, { "a": "d", "d": "f" } ] }, { "name": "filter, greater than or equal to string, double quotes", "selector": "$[?@.a>=\"c\"]", "document": [ { "a": "b", "d": "e" }, { "a": "c", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "c", "d": "f" }, { "a": "d", "d": "f" } ] }, { "name": "filter, greater than or equal to number", "selector": "$[?@.a>=10]", "document": [ { "a": 1, "d": "e" }, { "a": 10, "d": "e" }, { "a": "c", "d": "f" }, { "a": 20, "d": "f" } ], "result": [ { "a": 10, "d": "e" }, { "a": 20, "d": "f" } ] }, { "name": "filter, greater than or equal to null", "selector": "$[?@.a>=null]", "document": [ { "a": null, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": null, "d": "e" } ] }, { "name": "filter, greater than or equal to true", "selector": "$[?@.a>=true]", "document": [ { "a": true, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": true, "d": "e" } ] }, { "name": "filter, greater than or equal to false", "selector": "$[?@.a>=false]", "document": [ { "a": false, "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": false, "d": "e" } ] }, { "name": "filter, exists and not-equals null, absent from data", "selector": "$[?@.a&&@.a!=null]", "document": [ { "d": "e" }, { "a": "c", "d": "f" } ], "result": [ { "a": "c", "d": "f" } ] }, { "name": "filter, exists and exists, data false", "selector": "$[?@.a&&@.b]", "document": [ { "a": false, "b": false }, { "b": false }, { "c": false } ], "result": [ { "a": false, "b": false } ] }, { "name": "filter, exists or exists, data false", "selector": "$[?@.a||@.b]", "document": [ { "a": false, "b": false }, { "b": false }, { "c": false } ], "result": [ { "a": false, "b": false }, { "b": false } ] }, { "name": "filter, and", "selector": "$[?@.a>0&&@.a<10]", "document": [ { "a": -10, "d": "e" }, { "a": 5, "d": "f" }, { "a": 20, "d": "f" } ], "result": [ { "a": 5, "d": "f" } ] }, { "name": "filter, or", "selector": "$[?@.a=='b'||@.a=='d']", "document": [ { "a": "a", "d": "e" }, { "a": "b", "d": "f" }, { "a": "c", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "b", "d": "f" }, { "a": "d", "d": "f" } ] }, { "name": "filter, not expression", "selector": "$[?!(@.a=='b')]", "document": [ { "a": "a", "d": "e" }, { "a": "b", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "a", "d": "e" }, { "a": "d", "d": "f" } ] }, { "name": "filter, not exists", "selector": "$[?!@.a]", "document": [ { "a": "a", "d": "e" }, { "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "d": "f" } ] }, { "name": "filter, not exists, data null", "selector": "$[?!@.a]", "document": [ { "a": null, "d": "e" }, { "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "d": "f" } ] }, { "name": "filter, non-singular existence, wildcard", "selector": "$[?@.*]", "document": [ 1, [], [ 2 ], {}, { "a": 3 } ], "result": [ [ 2 ], { "a": 3 } ] }, { "name": "filter, non-singular existence, multiple", "selector": "$[?@[0, 0, 'a']]", "document": [ 1, [], [ 2 ], [ 2, 3 ], { "a": 3 }, { "b": 4 }, { "a": 3, "b": 4 } ], "result": [ [ 2 ], [ 2, 3 ], { "a": 3 }, { "a": 3, "b": 4 } ] }, { "name": "filter, non-singular existence, slice", "selector": "$[?@[0:2]]", "document": [ 1, [], [ 2 ], [ 2, 3, 4 ], {}, { "a": 3 } ], "result": [ [ 2 ], [ 2, 3, 4 ] ] }, { "name": "filter, non-singular existence, negated", "selector": "$[?!@.*]", "document": [ 1, [], [ 2 ], {}, { "a": 3 } ], "result": [ 1, [], {} ] }, { "name": "filter, non-singular query in comparison, slice", "selector": "$[?@[0:0]==0]", "invalid_selector": true }, { "name": "filter, non-singular query in comparison, all children", "selector": "$[?@[*]==0]", "invalid_selector": true }, { "name": "filter, non-singular query in comparison, descendants", "selector": "$[?@..a==0]", "invalid_selector": true }, { "name": "filter, non-singular query in comparison, combined", "selector": "$[?@.a[*].a==0]", "invalid_selector": true }, { "name": "filter, nested", "selector": "$[?@[?@>1]]", "document": [ [ 0 ], [ 0, 1 ], [ 0, 1, 2 ], [ 42 ] ], "result": [ [ 0, 1, 2 ], [ 42 ] ] }, { "name": "filter, name segment on primitive, selects nothing", "selector": "$[?@.a == 1]", "document": { "a": 1 }, "result": [] }, { "name": "filter, name segment on array, selects nothing", "selector": "$[?@['0'] == 5]", "document": [ [ 5, 6 ] ], "result": [] }, { "name": "filter, index segment on object, selects nothing", "selector": "$[?@[0] == 5]", "document": [ { "0": 5 } ], "result": [] }, { "name": "filter, relative non-singular query, index, equal", "selector": "$[?(@[0, 0]==42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, index, not equal", "selector": "$[?(@[0, 0]!=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, index, less-or-equal", "selector": "$[?(@[0, 0]<=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, name, equal", "selector": "$[?(@['a', 'a']==42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, name, not equal", "selector": "$[?(@['a', 'a']!=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, name, less-or-equal", "selector": "$[?(@['a', 'a']<=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, combined, equal", "selector": "$[?(@[0, '0']==42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, combined, not equal", "selector": "$[?(@[0, '0']!=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, combined, less-or-equal", "selector": "$[?(@[0, '0']<=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, wildcard, equal", "selector": "$[?(@.*==42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, wildcard, not equal", "selector": "$[?(@.*!=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, wildcard, less-or-equal", "selector": "$[?(@.*<=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, slice, equal", "selector": "$[?(@[0:0]==42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, slice, not equal", "selector": "$[?(@[0:0]!=42)]", "invalid_selector": true }, { "name": "filter, relative non-singular query, slice, less-or-equal", "selector": "$[?(@[0:0]<=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, index, equal", "selector": "$[?($[0, 0]==42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, index, not equal", "selector": "$[?($[0, 0]!=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, index, less-or-equal", "selector": "$[?($[0, 0]<=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, name, equal", "selector": "$[?($['a', 'a']==42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, name, not equal", "selector": "$[?($['a', 'a']!=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, name, less-or-equal", "selector": "$[?($['a', 'a']<=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, combined, equal", "selector": "$[?($[0, '0']==42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, combined, not equal", "selector": "$[?($[0, '0']!=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, combined, less-or-equal", "selector": "$[?($[0, '0']<=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, wildcard, equal", "selector": "$[?($.*==42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, wildcard, not equal", "selector": "$[?($.*!=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, wildcard, less-or-equal", "selector": "$[?($.*<=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, slice, equal", "selector": "$[?($[0:0]==42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, slice, not equal", "selector": "$[?($[0:0]!=42)]", "invalid_selector": true }, { "name": "filter, absolute non-singular query, slice, less-or-equal", "selector": "$[?($[0:0]<=42)]", "invalid_selector": true }, { "name": "filter, multiple selectors", "selector": "$[?@.a,?@.b]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ] }, { "name": "filter, multiple selectors, comparison", "selector": "$[?@.a=='b',?@.b=='x']", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "filter, multiple selectors, overlapping", "selector": "$[?@.a,?@.d]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" }, { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ] }, { "name": "filter, multiple selectors, filter and index", "selector": "$[?@.a,1]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ] }, { "name": "filter, multiple selectors, filter and wildcard", "selector": "$[?@.a,*]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" }, { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ] }, { "name": "filter, multiple selectors, filter and slice", "selector": "$[?@.a,1:]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" }, { "g": "h" } ], "result": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" }, { "g": "h" } ] }, { "name": "filter, multiple selectors, comparison filter, index and slice", "selector": "$[1, ?@.a=='b', 1:]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "b": "c", "d": "f" }, { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ] }, { "name": "filter, equals number, zero and negative zero", "selector": "$[?@.a==-0]", "document": [ { "a": 0, "d": "e" }, { "a": 0.1, "d": "f" }, { "a": "0", "d": "g" } ], "result": [ { "a": 0, "d": "e" } ] }, { "name": "filter, equals number, with and without decimal fraction", "selector": "$[?@.a==1.0]", "document": [ { "a": 1, "d": "e" }, { "a": 2, "d": "f" }, { "a": "1", "d": "g" } ], "result": [ { "a": 1, "d": "e" } ] }, { "name": "filter, equals number, exponent", "selector": "$[?@.a==1e2]", "document": [ { "a": 100, "d": "e" }, { "a": 100.1, "d": "f" }, { "a": "100", "d": "g" } ], "result": [ { "a": 100, "d": "e" } ] }, { "name": "filter, equals number, positive exponent", "selector": "$[?@.a==1e+2]", "document": [ { "a": 100, "d": "e" }, { "a": 100.1, "d": "f" }, { "a": "100", "d": "g" } ], "result": [ { "a": 100, "d": "e" } ] }, { "name": "filter, equals number, negative exponent", "selector": "$[?@.a==1e-2]", "document": [ { "a": 0.01, "d": "e" }, { "a": 0.02, "d": "f" }, { "a": "0.01", "d": "g" } ], "result": [ { "a": 0.01, "d": "e" } ] }, { "name": "filter, equals number, decimal fraction", "selector": "$[?@.a==1.1]", "document": [ { "a": 1.1, "d": "e" }, { "a": 1, "d": "f" }, { "a": "1.1", "d": "g" } ], "result": [ { "a": 1.1, "d": "e" } ] }, { "name": "filter, equals number, decimal fraction, no fractional digit", "selector": "$[?@.a==1.]", "invalid_selector": true }, { "name": "filter, equals number, decimal fraction, exponent", "selector": "$[?@.a==1.1e2]", "document": [ { "a": 110, "d": "e" }, { "a": 110.1, "d": "f" }, { "a": "110", "d": "g" } ], "result": [ { "a": 110, "d": "e" } ] }, { "name": "filter, equals number, decimal fraction, positive exponent", "selector": "$[?@.a==1.1e+2]", "document": [ { "a": 110, "d": "e" }, { "a": 110.1, "d": "f" }, { "a": "110", "d": "g" } ], "result": [ { "a": 110, "d": "e" } ] }, { "name": "filter, equals number, decimal fraction, negative exponent", "selector": "$[?@.a==1.1e-2]", "document": [ { "a": 0.011, "d": "e" }, { "a": 0.012, "d": "f" }, { "a": "0.011", "d": "g" } ], "result": [ { "a": 0.011, "d": "e" } ] }, { "name": "filter, equals, special nothing", "selector": "$.values[?length(@.a) == value($..c)]", "document": { "c": "cd", "values": [ { "a": "ab" }, { "c": "d" }, { "a": null } ] }, "result": [ { "c": "d" }, { "a": null } ] }, { "name": "filter, object data", "selector": "$[?@<3]", "document": { "a": 1, "b": 2, "c": 3 }, "results": [ [ 1, 2 ], [ 2, 1 ] ] }, { "name": "filter, and binds more tightly than or", "selector": "$[?@.a || @.b && @.b]", "document": [ { "a": 1 } ], "result": [ { "a": 1 } ] }, { "name": "filter, left to right evaluation", "selector": "$[?@.b && @.b || @.a]", "document": [ { "a": 1 } ], "result": [ { "a": 1 } ] }, { "name": "filter, group terms, left", "selector": "$[?(@.a || @.b) && @.a]", "document": [ { "a": 1 } ], "result": [ { "a": 1 } ] }, { "name": "filter, group terms, right", "selector": "$[?@.a && (@.b || @.a)]", "document": [ { "a": 1 } ], "result": [ { "a": 1 } ] }, { "name": "filter, group terms, or before and", "selector": "$[?(@.a || @.b) && @.b]", "document": [ { "a": 1 } ], "result": [] }, { "name": "index selector, first element", "selector": "$[0]", "document": [ "first", "second" ], "result": [ "first" ] }, { "name": "index selector, second element", "selector": "$[1]", "document": [ "first", "second" ], "result": [ "second" ] }, { "name": "index selector, out of bound", "selector": "$[2]", "document": [ "first", "second" ], "result": [] }, { "name": "index selector, overflowing index", "selector": "$[231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true }, { "name": "index selector, not actually an index, overflowing index leads into general text", "selector": "$[231584178474632390847141970017375815706539969331281128078915168SomeRandomText]", "invalid_selector": true }, { "name": "index selector, negative", "selector": "$[-1]", "document": [ "first", "second" ], "result": [ "second" ] }, { "name": "index selector, more negative", "selector": "$[-2]", "document": [ "first", "second" ], "result": [ "first" ] }, { "name": "index selector, negative out of bound", "selector": "$[-3]", "document": [ "first", "second" ], "result": [] }, { "name": "index selector, on object", "selector": "$[0]", "document": { "foo": 1 }, "result": [] }, { "name": "index selector, leading 0", "selector": "$[01]", "invalid_selector": true }, { "name": "index selector, leading -0", "selector": "$[-01]", "invalid_selector": true }, { "name": "name selector, double quotes", "selector": "$[\"a\"]", "document": { "a": "A", "b": "B" }, "result": [ "A" ] }, { "name": "name selector, double quotes, absent data", "selector": "$[\"c\"]", "document": { "a": "A", "b": "B" }, "result": [] }, { "name": "name selector, double quotes, array data", "selector": "$[\"a\"]", "document": [ "first", "second" ], "result": [] }, { "name": "name selector, double quotes, embedded U+0000", "selector": "$[\"\u0000\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0001", "selector": "$[\"\u0001\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0002", "selector": "$[\"\u0002\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0003", "selector": "$[\"\u0003\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0004", "selector": "$[\"\u0004\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0005", "selector": "$[\"\u0005\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0006", "selector": "$[\"\u0006\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0007", "selector": "$[\"\u0007\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0008", "selector": "$[\"\b\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0009", "selector": "$[\"\t\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+000A", "selector": "$[\"\n\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+000B", "selector": "$[\"\u000b\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+000C", "selector": "$[\"\f\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+000D", "selector": "$[\"\r\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+000E", "selector": "$[\"\u000e\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+000F", "selector": "$[\"\u000f\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0010", "selector": "$[\"\u0010\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0011", "selector": "$[\"\u0011\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0012", "selector": "$[\"\u0012\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0013", "selector": "$[\"\u0013\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0014", "selector": "$[\"\u0014\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0015", "selector": "$[\"\u0015\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0016", "selector": "$[\"\u0016\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0017", "selector": "$[\"\u0017\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0018", "selector": "$[\"\u0018\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0019", "selector": "$[\"\u0019\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+001A", "selector": "$[\"\u001a\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+001B", "selector": "$[\"\u001b\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+001C", "selector": "$[\"\u001c\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+001D", "selector": "$[\"\u001d\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+001E", "selector": "$[\"\u001e\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+001F", "selector": "$[\"\u001f\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded U+0020", "selector": "$[\" \"]", "document": { " ": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped double quote", "selector": "$[\"\\\"\"]", "document": { "\"": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped reverse solidus", "selector": "$[\"\\\\\"]", "document": { "\\": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped solidus", "selector": "$[\"\\/\"]", "document": { "/": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped backspace", "selector": "$[\"\\b\"]", "document": { "\b": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped form feed", "selector": "$[\"\\f\"]", "document": { "\f": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped line feed", "selector": "$[\"\\n\"]", "document": { "\n": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped carriage return", "selector": "$[\"\\r\"]", "document": { "\r": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped tab", "selector": "$[\"\\t\"]", "document": { "\t": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped ☺, upper case hex", "selector": "$[\"\\u263A\"]", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, escaped ☺, lower case hex", "selector": "$[\"\\u263a\"]", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, surrogate pair 𝄞", "selector": "$[\"\\uD834\\uDD1E\"]", "document": { "𝄞": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, surrogate pair 😀", "selector": "$[\"\\uD83D\\uDE00\"]", "document": { "😀": "A" }, "result": [ "A" ] }, { "name": "name selector, double quotes, invalid escaped single quote", "selector": "$[\"\\'\"]", "invalid_selector": true }, { "name": "name selector, double quotes, embedded double quote", "selector": "$[\"\"\"]", "invalid_selector": true }, { "name": "name selector, double quotes, incomplete escape", "selector": "$[\"\\\"]", "invalid_selector": true }, { "name": "name selector, single quotes", "selector": "$['a']", "document": { "a": "A", "b": "B" }, "result": [ "A" ] }, { "name": "name selector, single quotes, absent data", "selector": "$['c']", "document": { "a": "A", "b": "B" }, "result": [] }, { "name": "name selector, single quotes, array data", "selector": "$['a']", "document": [ "first", "second" ], "result": [] }, { "name": "name selector, single quotes, embedded U+0000", "selector": "$['\u0000']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0001", "selector": "$['\u0001']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0002", "selector": "$['\u0002']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0003", "selector": "$['\u0003']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0004", "selector": "$['\u0004']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0005", "selector": "$['\u0005']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0006", "selector": "$['\u0006']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0007", "selector": "$['\u0007']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0008", "selector": "$['\b']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0009", "selector": "$['\t']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+000A", "selector": "$['\n']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+000B", "selector": "$['\u000b']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+000C", "selector": "$['\f']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+000D", "selector": "$['\r']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+000E", "selector": "$['\u000e']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+000F", "selector": "$['\u000f']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0010", "selector": "$['\u0010']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0011", "selector": "$['\u0011']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0012", "selector": "$['\u0012']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0013", "selector": "$['\u0013']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0014", "selector": "$['\u0014']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0015", "selector": "$['\u0015']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0016", "selector": "$['\u0016']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0017", "selector": "$['\u0017']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0018", "selector": "$['\u0018']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0019", "selector": "$['\u0019']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+001A", "selector": "$['\u001a']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+001B", "selector": "$['\u001b']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+001C", "selector": "$['\u001c']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+001D", "selector": "$['\u001d']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+001E", "selector": "$['\u001e']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+001F", "selector": "$['\u001f']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded U+0020", "selector": "$[' ']", "document": { " ": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped single quote", "selector": "$['\\'']", "document": { "'": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped reverse solidus", "selector": "$['\\\\']", "document": { "\\": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped solidus", "selector": "$['\\/']", "document": { "/": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped backspace", "selector": "$['\\b']", "document": { "\b": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped form feed", "selector": "$['\\f']", "document": { "\f": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped line feed", "selector": "$['\\n']", "document": { "\n": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped carriage return", "selector": "$['\\r']", "document": { "\r": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped tab", "selector": "$['\\t']", "document": { "\t": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped ☺, upper case hex", "selector": "$['\\u263A']", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, escaped ☺, lower case hex", "selector": "$['\\u263a']", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, surrogate pair 𝄞", "selector": "$['\\uD834\\uDD1E']", "document": { "𝄞": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, surrogate pair 😀", "selector": "$['\\uD83D\\uDE00']", "document": { "😀": "A" }, "result": [ "A" ] }, { "name": "name selector, single quotes, invalid escaped double quote", "selector": "$['\\\"']", "invalid_selector": true }, { "name": "name selector, single quotes, embedded single quote", "selector": "$[''']", "invalid_selector": true }, { "name": "name selector, single quotes, incomplete escape", "selector": "$['\\']", "invalid_selector": true }, { "name": "name selector, double quotes, empty", "selector": "$[\"\"]", "document": { "a": "A", "b": "B", "": "C" }, "result": [ "C" ] }, { "name": "name selector, single quotes, empty", "selector": "$['']", "document": { "a": "A", "b": "B", "": "C" }, "result": [ "C" ] }, { "name": "slice selector, slice selector", "selector": "$[1:3]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 2 ] }, { "name": "slice selector, slice selector with step", "selector": "$[1:6:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 3, 5 ] }, { "name": "slice selector, slice selector with everything omitted, short form", "selector": "$[:]", "document": [ 0, 1, 2, 3 ], "result": [ 0, 1, 2, 3 ] }, { "name": "slice selector, slice selector with everything omitted, long form", "selector": "$[::]", "document": [ 0, 1, 2, 3 ], "result": [ 0, 1, 2, 3 ] }, { "name": "slice selector, slice selector with start omitted", "selector": "$[:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1 ] }, { "name": "slice selector, slice selector with start and end omitted", "selector": "$[::2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 2, 4, 6, 8 ] }, { "name": "slice selector, negative step with default start and end", "selector": "$[::-1]", "document": [ 0, 1, 2, 3 ], "result": [ 3, 2, 1, 0 ] }, { "name": "slice selector, negative step with default start", "selector": "$[:0:-1]", "document": [ 0, 1, 2, 3 ], "result": [ 3, 2, 1 ] }, { "name": "slice selector, negative step with default end", "selector": "$[2::-1]", "document": [ 0, 1, 2, 3 ], "result": [ 2, 1, 0 ] }, { "name": "slice selector, larger negative step", "selector": "$[::-2]", "document": [ 0, 1, 2, 3 ], "result": [ 3, 1 ] }, { "name": "slice selector, negative range with default step", "selector": "$[-1:-3]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [] }, { "name": "slice selector, negative range with negative step", "selector": "$[-1:-3:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8 ] }, { "name": "slice selector, negative range with larger negative step", "selector": "$[-1:-6:-2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 7, 5 ] }, { "name": "slice selector, larger negative range with larger negative step", "selector": "$[-1:-7:-2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 7, 5 ] }, { "name": "slice selector, negative from, positive to", "selector": "$[-5:7]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 5, 6 ] }, { "name": "slice selector, negative from", "selector": "$[-2:]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 8, 9 ] }, { "name": "slice selector, positive from, negative to", "selector": "$[1:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 2, 3, 4, 5, 6, 7, 8 ] }, { "name": "slice selector, negative from, positive to, negative step", "selector": "$[-1:1:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8, 7, 6, 5, 4, 3, 2 ] }, { "name": "slice selector, positive from, negative to, negative step", "selector": "$[7:-5:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 7, 6 ] }, { "name": "slice selector, too many colons", "selector": "$[1:2:3:4]", "invalid_selector": true }, { "name": "slice selector, non-integer array index", "selector": "$[1:2:a]", "invalid_selector": true }, { "name": "slice selector, zero step", "selector": "$[1:2:0]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [] }, { "name": "slice selector, empty range", "selector": "$[2:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [] }, { "name": "slice selector, slice selector with everything omitted with empty array", "selector": "$[:]", "document": [], "result": [] }, { "name": "slice selector, negative step with empty array", "selector": "$[::-1]", "document": [], "result": [] }, { "name": "slice selector, maximal range with positive step", "selector": "$[0:10]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] }, { "name": "slice selector, maximal range with negative step", "selector": "$[9:0:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8, 7, 6, 5, 4, 3, 2, 1 ] }, { "name": "slice selector, excessively large to value", "selector": "$[2:113667776004]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 2, 3, 4, 5, 6, 7, 8, 9 ] }, { "name": "slice selector, excessively small from value", "selector": "$[-113667776004:1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0 ] }, { "name": "slice selector, excessively large from value with negative step", "selector": "$[113667776004:0:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8, 7, 6, 5, 4, 3, 2, 1 ] }, { "name": "slice selector, excessively small to value with negative step", "selector": "$[3:-113667776004:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 3, 2, 1, 0 ] }, { "name": "slice selector, excessively large step", "selector": "$[1:10:113667776004]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1 ] }, { "name": "slice selector, excessively small step", "selector": "$[-1:-10:-113667776004]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9 ] }, { "name": "slice selector, overflowing to value", "selector": "$[2:231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true }, { "name": "slice selector, underflowing from value", "selector": "$[-231584178474632390847141970017375815706539969331281128078915168015826259279872:1]", "invalid_selector": true }, { "name": "slice selector, overflowing from value with negative step", "selector": "$[231584178474632390847141970017375815706539969331281128078915168015826259279872:0:-1]", "invalid_selector": true }, { "name": "slice selector, underflowing to value with negative step", "selector": "$[3:-231584178474632390847141970017375815706539969331281128078915168015826259279872:-1]", "invalid_selector": true }, { "name": "slice selector, overflowing step", "selector": "$[1:10:231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true }, { "name": "slice selector, underflowing step", "selector": "$[-1:-10:-231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true }, { "name": "functions, count, count function", "selector": "$[?count(@..*)>2]", "document": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ], "result": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" } ] }, { "name": "functions, count, single-node arg", "selector": "$[?count(@.a)>1]", "document": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ], "result": [] }, { "name": "functions, count, multiple-selector arg", "selector": "$[?count(@['a','d'])>1]", "document": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ], "result": [ { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ] }, { "name": "functions, count, non-query arg, number", "selector": "$[?count(1)>2]", "invalid_selector": true }, { "name": "functions, count, non-query arg, string", "selector": "$[?count('string')>2]", "invalid_selector": true }, { "name": "functions, count, non-query arg, true", "selector": "$[?count(true)>2]", "invalid_selector": true }, { "name": "functions, count, non-query arg, false", "selector": "$[?count(false)>2]", "invalid_selector": true }, { "name": "functions, count, non-query arg, null", "selector": "$[?count(null)>2]", "invalid_selector": true }, { "name": "functions, count, result must be compared", "selector": "$[?count(@..*)]", "invalid_selector": true }, { "name": "functions, count, no params", "selector": "$[?count()==1]", "invalid_selector": true }, { "name": "functions, count, too many params", "selector": "$[?count(@.a,@.b)==1]", "invalid_selector": true }, { "name": "functions, length, string data", "selector": "$[?length(@.a)>=2]", "document": [ { "a": "ab" }, { "a": "d" } ], "result": [ { "a": "ab" } ] }, { "name": "functions, length, string data, unicode", "selector": "$[?length(@)==2]", "document": [ "☺", "☺☺", "☺☺☺", "ж", "жж", "жжж", "磨", "阿美", "形声字" ], "result": [ "☺☺", "жж", "阿美" ] }, { "name": "functions, length, array data", "selector": "$[?length(@.a)>=2]", "document": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ] } ], "result": [ { "a": [ 1, 2, 3 ] } ] }, { "name": "functions, length, missing data", "selector": "$[?length(@.a)>=2]", "document": [ { "d": "f" } ], "result": [] }, { "name": "functions, length, number arg", "selector": "$[?length(1)>=2]", "document": [ { "d": "f" } ], "result": [] }, { "name": "functions, length, true arg", "selector": "$[?length(true)>=2]", "document": [ { "d": "f" } ], "result": [] }, { "name": "functions, length, false arg", "selector": "$[?length(false)>=2]", "document": [ { "d": "f" } ], "result": [] }, { "name": "functions, length, null arg", "selector": "$[?length(null)>=2]", "document": [ { "d": "f" } ], "result": [] }, { "name": "functions, length, result must be compared", "selector": "$[?length(@.a)]", "invalid_selector": true }, { "name": "functions, length, no params", "selector": "$[?length()==1]", "invalid_selector": true }, { "name": "functions, length, too many params", "selector": "$[?length(@.a,@.b)==1]", "invalid_selector": true }, { "name": "functions, length, non-singular query arg", "selector": "$[?length(@.*)<3]", "invalid_selector": true }, { "name": "functions, length, arg is a function expression", "selector": "$.values[?length(@.a)==length(value($..c))]", "document": { "c": "cd", "values": [ { "a": "ab" }, { "a": "d" } ] }, "result": [ { "a": "ab" } ] }, { "name": "functions, length, arg is special nothing", "selector": "$[?length(value(@.a))>0]", "document": [ { "a": "ab" }, { "c": "d" }, { "a": null } ], "result": [ { "a": "ab" } ] }, { "name": "functions, match, found match", "selector": "$[?match(@.a, 'a.*')]", "document": [ { "a": "ab" } ], "result": [ { "a": "ab" } ] }, { "name": "functions, match, double quotes", "selector": "$[?match(@.a, \"a.*\")]", "document": [ { "a": "ab" } ], "result": [ { "a": "ab" } ] }, { "name": "functions, match, regex from the document", "selector": "$.values[?match(@, $.regex)]", "document": { "regex": "b.?b", "values": [ "abc", "bcd", "bab", "bba", "bbab", "b", true, [], {} ] }, "result": [ "bab" ] }, { "name": "functions, match, don't select match", "selector": "$[?!match(@.a, 'a.*')]", "document": [ { "a": "ab" } ], "result": [] }, { "name": "functions, match, not a match", "selector": "$[?match(@.a, 'a.*')]", "document": [ { "a": "bc" } ], "result": [] }, { "name": "functions, match, select non-match", "selector": "$[?!match(@.a, 'a.*')]", "document": [ { "a": "bc" } ], "result": [ { "a": "bc" } ] }, { "name": "functions, match, non-string first arg", "selector": "$[?match(1, 'a.*')]", "document": [ { "a": "bc" } ], "result": [] }, { "name": "functions, match, non-string second arg", "selector": "$[?match(@.a, 1)]", "document": [ { "a": "bc" } ], "result": [] }, { "name": "functions, match, filter, match function, unicode char class, uppercase", "selector": "$[?match(@, '\\\\p{Lu}')]", "document": [ "ж", "Ж", "1", "жЖ", true, [], {} ], "result": [ "Ж" ] }, { "name": "functions, match, filter, match function, unicode char class negated, uppercase", "selector": "$[?match(@, '\\\\P{Lu}')]", "document": [ "ж", "Ж", "1", true, [], {} ], "result": [ "ж", "1" ] }, { "name": "functions, match, filter, match function, unicode, surrogate pair", "selector": "$[?match(@, 'a.b')]", "document": [ "a𐄁b", "ab", "1", true, [], {} ], "result": [ "a𐄁b" ] }, { "name": "functions, match, result cannot be compared", "selector": "$[?match(@.a, 'a.*')==true]", "invalid_selector": true }, { "name": "functions, match, too few params", "selector": "$[?match(@.a)==1]", "invalid_selector": true }, { "name": "functions, match, too many params", "selector": "$[?match(@.a,@.b,@.c)==1]", "invalid_selector": true }, { "name": "functions, match, arg is a function expression", "selector": "$.values[?match(@.a, value($..['regex']))]", "document": { "regex": "a.*", "values": [ { "a": "ab" }, { "a": "ba" } ] }, "result": [ { "a": "ab" } ] }, { "name": "functions, search, at the end", "selector": "$[?search(@.a, 'a.*')]", "document": [ { "a": "the end is ab" } ], "result": [ { "a": "the end is ab" } ] }, { "name": "functions, search, double quotes", "selector": "$[?search(@.a, \"a.*\")]", "document": [ { "a": "the end is ab" } ], "result": [ { "a": "the end is ab" } ] }, { "name": "functions, search, at the start", "selector": "$[?search(@.a, 'a.*')]", "document": [ { "a": "ab is at the start" } ], "result": [ { "a": "ab is at the start" } ] }, { "name": "functions, search, in the middle", "selector": "$[?search(@.a, 'a.*')]", "document": [ { "a": "contains two matches" } ], "result": [ { "a": "contains two matches" } ] }, { "name": "functions, search, regex from the document", "selector": "$.values[?search(@, $.regex)]", "document": { "regex": "b.?b", "values": [ "abc", "bcd", "bab", "bba", "bbab", "b", true, [], {} ] }, "result": [ "bab", "bba", "bbab" ] }, { "name": "functions, search, don't select match", "selector": "$[?!search(@.a, 'a.*')]", "document": [ { "a": "contains two matches" } ], "result": [] }, { "name": "functions, search, not a match", "selector": "$[?search(@.a, 'a.*')]", "document": [ { "a": "bc" } ], "result": [] }, { "name": "functions, search, select non-match", "selector": "$[?!search(@.a, 'a.*')]", "document": [ { "a": "bc" } ], "result": [ { "a": "bc" } ] }, { "name": "functions, search, non-string first arg", "selector": "$[?search(1, 'a.*')]", "document": [ { "a": "bc" } ], "result": [] }, { "name": "functions, search, non-string second arg", "selector": "$[?search(@.a, 1)]", "document": [ { "a": "bc" } ], "result": [] }, { "name": "functions, search, filter, search function, unicode char class, uppercase", "selector": "$[?search(@, '\\\\p{Lu}')]", "document": [ "ж", "Ж", "1", "жЖ", true, [], {} ], "result": [ "Ж", "жЖ" ] }, { "name": "functions, search, filter, search function, unicode char class negated, uppercase", "selector": "$[?search(@, '\\\\P{Lu}')]", "document": [ "ж", "Ж", "1", true, [], {} ], "result": [ "ж", "1" ] }, { "name": "functions, search, filter, search function, unicode, surrogate pair", "selector": "$[?search(@, 'a.b')]", "document": [ "a𐄁bc", "abc", "1", true, [], {} ], "result": [ "a𐄁bc" ] }, { "name": "functions, search, result cannot be compared", "selector": "$[?search(@.a, 'a.*')==true]", "invalid_selector": true }, { "name": "functions, search, too few params", "selector": "$[?search(@.a)]", "invalid_selector": true }, { "name": "functions, search, too many params", "selector": "$[?search(@.a,@.b,@.c)]", "invalid_selector": true }, { "name": "functions, search, arg is a function expression", "selector": "$.values[?search(@, value($..['regex']))]", "document": { "regex": "b.?b", "values": [ "abc", "bcd", "bab", "bba", "bbab", "b", true, [], {} ] }, "result": [ "bab", "bba", "bbab" ] }, { "name": "functions, value, single-value nodelist", "selector": "$[?value(@.*)==4]", "document": [ [ 4 ], { "foo": 4 }, [ 5 ], { "foo": 5 }, 4 ], "result": [ [ 4 ], { "foo": 4 } ] }, { "name": "functions, value, multi-value nodelist", "selector": "$[?value(@.*)==4]", "document": [ [ 4, 4 ], { "foo": 4, "bar": 4 } ], "result": [] }, { "name": "functions, value, too few params", "selector": "$[?value()==4]", "invalid_selector": true }, { "name": "functions, value, too many params", "selector": "$[?value(@.a,@.b)==4]", "invalid_selector": true }, { "name": "functions, value, result must be compared", "selector": "$[?value(@.a)]", "invalid_selector": true }, { "name": "whitespace, filter, space between question mark and expression", "selector": "$[? @.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, newline between question mark and expression", "selector": "$[?\n@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, tab between question mark and expression", "selector": "$[?\t@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, return between question mark and expression", "selector": "$[?\r@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, space between question mark and parenthesized expression", "selector": "$[? (@.a)]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, newline between question mark and parenthesized expression", "selector": "$[?\n(@.a)]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, tab between question mark and parenthesized expression", "selector": "$[?\t(@.a)]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, return between question mark and parenthesized expression", "selector": "$[?\r(@.a)]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, space between parenthesized expression and bracket", "selector": "$[?(@.a) ]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, newline between parenthesized expression and bracket", "selector": "$[?(@.a)\n]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, tab between parenthesized expression and bracket", "selector": "$[?(@.a)\t]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, return between parenthesized expression and bracket", "selector": "$[?(@.a)\r]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, space between bracket and question mark", "selector": "$[ ?@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, newline between bracket and question mark", "selector": "$[\n?@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, tab between bracket and question mark", "selector": "$[\t?@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, filter, return between bracket and question mark", "selector": "$[\r?@.a]", "document": [ { "a": "b", "d": "e" }, { "b": "c", "d": "f" } ], "result": [ { "a": "b", "d": "e" } ] }, { "name": "whitespace, functions, space between function name and parenthesis", "selector": "$[?count (@.*)==1]", "invalid_selector": true }, { "name": "whitespace, functions, newline between function name and parenthesis", "selector": "$[?count\n(@.*)==1]", "invalid_selector": true }, { "name": "whitespace, functions, tab between function name and parenthesis", "selector": "$[?count\t(@.*)==1]", "invalid_selector": true }, { "name": "whitespace, functions, return between function name and parenthesis", "selector": "$[?count\r(@.*)==1]", "invalid_selector": true }, { "name": "whitespace, functions, space between parenthesis and arg", "selector": "$[?count( @.*)==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, newline between parenthesis and arg", "selector": "$[?count(\n@.*)==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, tab between parenthesis and arg", "selector": "$[?count(\t@.*)==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, return between parenthesis and arg", "selector": "$[?count(\r@.*)==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, space between arg and comma", "selector": "$[?search(@ ,'[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, newline between arg and comma", "selector": "$[?search(@\n,'[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, tab between arg and comma", "selector": "$[?search(@\t,'[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, return between arg and comma", "selector": "$[?search(@\r,'[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, space between comma and arg", "selector": "$[?search(@, '[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, newline between comma and arg", "selector": "$[?search(@,\n'[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, tab between comma and arg", "selector": "$[?search(@,\t'[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, return between comma and arg", "selector": "$[?search(@,\r'[a-z]+')]", "document": [ "foo", "123" ], "result": [ "foo" ] }, { "name": "whitespace, functions, space between arg and parenthesis", "selector": "$[?count(@.* )==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, newline between arg and parenthesis", "selector": "$[?count(@.*\n)==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, tab between arg and parenthesis", "selector": "$[?count(@.*\t)==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, return between arg and parenthesis", "selector": "$[?count(@.*\r)==1]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, functions, spaces in a relative singular selector", "selector": "$[?length(@ .a .b) == 3]", "document": [ { "a": { "b": "foo" } }, {} ], "result": [ { "a": { "b": "foo" } } ] }, { "name": "whitespace, functions, newlines in a relative singular selector", "selector": "$[?length(@\n.a\n.b) == 3]", "document": [ { "a": { "b": "foo" } }, {} ], "result": [ { "a": { "b": "foo" } } ] }, { "name": "whitespace, functions, tabs in a relative singular selector", "selector": "$[?length(@\t.a\t.b) == 3]", "document": [ { "a": { "b": "foo" } }, {} ], "result": [ { "a": { "b": "foo" } } ] }, { "name": "whitespace, functions, returns in a relative singular selector", "selector": "$[?length(@\r.a\r.b) == 3]", "document": [ { "a": { "b": "foo" } }, {} ], "result": [ { "a": { "b": "foo" } } ] }, { "name": "whitespace, functions, spaces in an absolute singular selector", "selector": "$..[?length(@)==length($ [0] .a)]", "document": [ { "a": "foo" }, {} ], "result": [ "foo" ] }, { "name": "whitespace, functions, newlines in an absolute singular selector", "selector": "$..[?length(@)==length($\n[0]\n.a)]", "document": [ { "a": "foo" }, {} ], "result": [ "foo" ] }, { "name": "whitespace, functions, tabs in an absolute singular selector", "selector": "$..[?length(@)==length($\t[0]\t.a)]", "document": [ { "a": "foo" }, {} ], "result": [ "foo" ] }, { "name": "whitespace, functions, returns in an absolute singular selector", "selector": "$..[?length(@)==length($\r[0]\r.a)]", "document": [ { "a": "foo" }, {} ], "result": [ "foo" ] }, { "name": "whitespace, operators, space before ||", "selector": "$[?@.a ||@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, newline before ||", "selector": "$[?@.a\n||@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, tab before ||", "selector": "$[?@.a\t||@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, return before ||", "selector": "$[?@.a\r||@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, space after ||", "selector": "$[?@.a|| @.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, newline after ||", "selector": "$[?@.a||\n@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, tab after ||", "selector": "$[?@.a||\t@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, return after ||", "selector": "$[?@.a||\r@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "c": 3 } ], "result": [ { "a": 1 }, { "b": 2 } ] }, { "name": "whitespace, operators, space before &&", "selector": "$[?@.a &&@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline before &&", "selector": "$[?@.a\n&&@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab before &&", "selector": "$[?@.a\t&&@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return before &&", "selector": "$[?@.a\r&&@.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space after &&", "selector": "$[?@.a&& @.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline after &&", "selector": "$[?@.a&& @.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab after &&", "selector": "$[?@.a&& @.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return after &&", "selector": "$[?@.a&& @.b]", "document": [ { "a": 1 }, { "b": 2 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space before ==", "selector": "$[?@.a ==@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, newline before ==", "selector": "$[?@.a\n==@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, tab before ==", "selector": "$[?@.a\t==@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, return before ==", "selector": "$[?@.a\r==@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, space after ==", "selector": "$[?@.a== @.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, newline after ==", "selector": "$[?@.a==\n@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, tab after ==", "selector": "$[?@.a==\t@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, return after ==", "selector": "$[?@.a==\r@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 1 } ] }, { "name": "whitespace, operators, space before !=", "selector": "$[?@.a !=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline before !=", "selector": "$[?@.a\n!=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab before !=", "selector": "$[?@.a\t!=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return before !=", "selector": "$[?@.a\r!=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space after !=", "selector": "$[?@.a!= @.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline after !=", "selector": "$[?@.a!=\n@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab after !=", "selector": "$[?@.a!=\t@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return after !=", "selector": "$[?@.a!=\r@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space before <", "selector": "$[?@.a <@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline before <", "selector": "$[?@.a\n<@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab before <", "selector": "$[?@.a\t<@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return before <", "selector": "$[?@.a\r<@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space after <", "selector": "$[?@.a< @.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline after <", "selector": "$[?@.a<\n@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab after <", "selector": "$[?@.a<\t@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return after <", "selector": "$[?@.a<\r@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space before >", "selector": "$[?@.b >@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline before >", "selector": "$[?@.b\n>@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab before >", "selector": "$[?@.b\t>@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return before >", "selector": "$[?@.b\r>@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space after >", "selector": "$[?@.b> @.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline after >", "selector": "$[?@.b>\n@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab after >", "selector": "$[?@.b>\t@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return after >", "selector": "$[?@.b>\r@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ], "result": [ { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space before <=", "selector": "$[?@.a <=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline before <=", "selector": "$[?@.a\n<=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab before <=", "selector": "$[?@.a\t<=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return before <=", "selector": "$[?@.a\r<=@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space after <=", "selector": "$[?@.a<= @.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline after <=", "selector": "$[?@.a<=\n@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab after <=", "selector": "$[?@.a<=\t@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return after <=", "selector": "$[?@.a<=\r@.b]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space before >=", "selector": "$[?@.b >=@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline before >=", "selector": "$[?@.b\n>=@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab before >=", "selector": "$[?@.b\t>=@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return before >=", "selector": "$[?@.b\r>=@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space after >=", "selector": "$[?@.b>= @.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, newline after >=", "selector": "$[?@.b>=\n@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, tab after >=", "selector": "$[?@.b>=\t@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, return after >=", "selector": "$[?@.b>=\r@.a]", "document": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 }, { "a": 2, "b": 1 } ], "result": [ { "a": 1, "b": 1 }, { "a": 1, "b": 2 } ] }, { "name": "whitespace, operators, space between logical not and test expression", "selector": "$[?! @.a]", "document": [ { "a": "a", "d": "e" }, { "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "d": "f" } ] }, { "name": "whitespace, operators, newline between logical not and test expression", "selector": "$[?!\n@.a]", "document": [ { "a": "a", "d": "e" }, { "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "d": "f" } ] }, { "name": "whitespace, operators, tab between logical not and test expression", "selector": "$[?!\t@.a]", "document": [ { "a": "a", "d": "e" }, { "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "d": "f" } ] }, { "name": "whitespace, operators, return between logical not and test expression", "selector": "$[?!\r@.a]", "document": [ { "a": "a", "d": "e" }, { "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "d": "f" } ] }, { "name": "whitespace, operators, space between logical not and parenthesized expression", "selector": "$[?! (@.a=='b')]", "document": [ { "a": "a", "d": "e" }, { "a": "b", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "a", "d": "e" }, { "a": "d", "d": "f" } ] }, { "name": "whitespace, operators, newline between logical not and parenthesized expression", "selector": "$[?!\n(@.a=='b')]", "document": [ { "a": "a", "d": "e" }, { "a": "b", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "a", "d": "e" }, { "a": "d", "d": "f" } ] }, { "name": "whitespace, operators, tab between logical not and parenthesized expression", "selector": "$[?!\t(@.a=='b')]", "document": [ { "a": "a", "d": "e" }, { "a": "b", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "a", "d": "e" }, { "a": "d", "d": "f" } ] }, { "name": "whitespace, operators, return between logical not and parenthesized expression", "selector": "$[?!\r(@.a=='b')]", "document": [ { "a": "a", "d": "e" }, { "a": "b", "d": "f" }, { "a": "d", "d": "f" } ], "result": [ { "a": "a", "d": "e" }, { "a": "d", "d": "f" } ] }, { "name": "whitespace, selectors, space between root and bracket", "selector": "$ ['a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, newline between root and bracket", "selector": "$\n['a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, tab between root and bracket", "selector": "$\t['a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, return between root and bracket", "selector": "$\r['a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, space between bracket and bracket", "selector": "$['a'] ['b']", "document": { "a": { "b": "ab" } }, "result": [ "ab" ] }, { "name": "whitespace, selectors, newline between root and bracket", "selector": "$['a'] \n['b']", "document": { "a": { "b": "ab" } }, "result": [ "ab" ] }, { "name": "whitespace, selectors, tab between root and bracket", "selector": "$['a'] \t['b']", "document": { "a": { "b": "ab" } }, "result": [ "ab" ] }, { "name": "whitespace, selectors, return between root and bracket", "selector": "$['a'] \r['b']", "document": { "a": { "b": "ab" } }, "result": [ "ab" ] }, { "name": "whitespace, selectors, space between root and dot", "selector": "$ .a", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, newline between root and dot", "selector": "$\n.a", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, tab between root and dot", "selector": "$\t.a", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, return between root and dot", "selector": "$\r.a", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, space between dot and name", "selector": "$. a", "invalid_selector": true }, { "name": "whitespace, selectors, newline between dot and name", "selector": "$.\na", "invalid_selector": true }, { "name": "whitespace, selectors, tab between dot and name", "selector": "$.\ta", "invalid_selector": true }, { "name": "whitespace, selectors, return between dot and name", "selector": "$.\ra", "invalid_selector": true }, { "name": "whitespace, selectors, space between recursive descent and name", "selector": "$.. a", "invalid_selector": true }, { "name": "whitespace, selectors, newline between recursive descent and name", "selector": "$..\na", "invalid_selector": true }, { "name": "whitespace, selectors, tab between recursive descent and name", "selector": "$..\ta", "invalid_selector": true }, { "name": "whitespace, selectors, return between recursive descent and name", "selector": "$..\ra", "invalid_selector": true }, { "name": "whitespace, selectors, space between bracket and selector", "selector": "$[ 'a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, newline between bracket and selector", "selector": "$[\n'a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, tab between bracket and selector", "selector": "$[\t'a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, return between bracket and selector", "selector": "$[\r'a']", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, space between selector and bracket", "selector": "$['a' ]", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, newline between selector and bracket", "selector": "$['a'\n]", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, tab between selector and bracket", "selector": "$['a'\t]", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, return between selector and bracket", "selector": "$['a'\r]", "document": { "a": "ab" }, "result": [ "ab" ] }, { "name": "whitespace, selectors, space between selector and comma", "selector": "$['a' ,'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, selectors, newline between selector and comma", "selector": "$['a'\n,'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, selectors, tab between selector and comma", "selector": "$['a'\t,'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, selectors, return between selector and comma", "selector": "$['a'\r,'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, selectors, space between comma and selector", "selector": "$['a', 'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, selectors, newline between comma and selector", "selector": "$['a',\n'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, selectors, tab between comma and selector", "selector": "$['a',\t'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, selectors, return between comma and selector", "selector": "$['a',\r'b']", "document": { "a": "ab", "b": "bc" }, "result": [ "ab", "bc" ] }, { "name": "whitespace, slice, space between start and colon", "selector": "$[1 :5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, newline between start and colon", "selector": "$[1\n:5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, tab between start and colon", "selector": "$[1\t:5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, return between start and colon", "selector": "$[1\r:5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, space between colon and end", "selector": "$[1: 5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, newline between colon and end", "selector": "$[1:\n5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, tab between colon and end", "selector": "$[1:\t5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, return between colon and end", "selector": "$[1:\r5:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, space between end and colon", "selector": "$[1:5 :2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, newline between end and colon", "selector": "$[1:5\n:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, tab between end and colon", "selector": "$[1:5\t:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, return between end and colon", "selector": "$[1:5\r:2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, space between colon and step", "selector": "$[1:5: 2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, newline between colon and step", "selector": "$[1:5:\n2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, tab between colon and step", "selector": "$[1:5:\t2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] }, { "name": "whitespace, slice, return between colon and step", "selector": "$[1:5:\r2]", "document": [ 1, 2, 3, 4, 5, 6 ], "result": [ 2, 4 ] } ] } build.sh100755001750001750 15114612756433 22045 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite#!/usr/bin/env sh set -e localDir=$(dirname "$0") node build.js "$localDir/tests" > "$localDir/cts.json" build.ps1100644001750001750 13314612756433 22133 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suitechcp 65001 $localDir=$PSScriptRoot node build.js "$localDir/tests" > "$localDir/cts.json" README.md100644001750001750 236414612756433 21716 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite# JSONPath Compliance Test Suite **WORK IN PROGRESS** This Compliance Test Suite follows, and usually lags behind, the [internet draft](https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-jsonpath). See [cts.json](cts.json) for the Compliance Test Suite. See the [Contributor Guide](./CONTRIBUTING.md) if you'd like to submit changes. To use this test suite, it's recommended you embed this repository as a git submodule of your implementation. ### Conventions Basic conventions around source file formatting are captured in the `.editorconfig` file. Many editors support that file natively. Others (such as VS code) require a plugin, see https://editorconfig.org/. ### Contributing To add or modify a test suite, edit the corresponding file in the `tests` directory. To generate `cts.json`, run the `build.sh` located in the root folder. Do not modify `cts.json` directly. More details are available in the [Contributor Guide](./CONTRIBUTING.md). ### Non-determinism Where the spec allows non-deterministic results for a given testcase, the testcase should specify an array of all the valid results (each of which is itself an array representing the resultant nodelist from the query) in the "results" member (and should not specify a "result" member).cts.schema.json100644001750001750 525114612756433 23360 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://raw.githubusercontent.com/jsonpath-standard/jsonpath-compliance-test-suite/main/cts.schema.json", "title": "Compliance Test Suite", "description": "JSONPath Compliance Test Suite", "type": "object", "properties": { "tests": { "description": "Individual test cases", "type": "array", "items": { "$ref": "#/$defs/test_case" } } }, "required": [ "tests" ], "$defs": { "test_case": { "type": "object", "properties": { "name": { "$ref": "#/$defs/test_case_name" }, "selector": { "$ref": "#/$defs/selector" }, "document": { "$ref": "#/$defs/document" }, "result": { "$ref": "#/$defs/test_case_result" }, "results": { "$ref": "#/$defs/test_case_results" }, "invalid_selector": { "$ref": "#/$defs/invalid_selector" } }, "required": [ "name", "selector" ], "oneOf": [ { "required": [ "document", "result" ], "properties": { "invalid_selector": false, "results": false } }, { "required": [ "document", "results" ], "properties": { "invalid_selector": false, "result": false } }, { "required": [ "invalid_selector" ], "properties": { "document": false, "result": false, "results": false } } ] }, "test_case_name": { "description": "The name of the test case", "type": "string", "pattern": "^\\S.*\\S$" }, "test_case_result": { "type": "array", "description": "The expected result of applying the selector to the document, contains all the matched values" }, "test_case_results": { "type": "array", "items": {"$ref": "#/$defs/test_case_result"}, "minItems": 2, "description": "An array of possible expected results of applying the selector to the document, each element of which contains all the matched values" }, "selector": { "description": "The JSONPath selector", "type": "string" }, "document": { "description": "The document, the selector is applied to" }, "invalid_selector": { "type": "boolean", "const": true, "description": "The flag indicating that the selector is not a valid JSONPath selector expression" } } } CONTRIBUTING.md100644001750001750 525314612756433 22670 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite# Contributing to jsonpath-compliance-test-suite The jsonpath-compliance-test-suite project team welcomes contributions from the community. ## Contribution Flow This is a rough outline of what a contributor's workflow looks like: - Create a topic branch from where you want to base your work - Make commits of logical units - Make sure your commit messages are in the proper format (see below) - Push your changes to a topic branch in your fork of the repository - Submit a pull request Example: ``` shell git remote add upstream https://github.com/jsonpath-standard/jsonpath-compliance-test-suite.git git checkout -b my-new-feature main git commit -a git push origin my-new-feature ``` ### Making changes to the Test Suite You need to have [Node.js](https://nodejs.org/en/) (v18 or higher) installed to build the Test Suite. To add or modify tests: - add/edit the corresponding file(s) in the `tests` directory - [optional] run the `build.sh` or `build.ps1` script located in the root folder\ (this will be performed automatically by GitHub CI after the pull request has been merged to `main`) - commit the changes to `tests` and `cts.json` Do not modify `cts.json` directly! ### Staying In Sync With Upstream When your branch gets out of sync with the jsonpath-standard/jsonpath-compliance-test-suite/main branch, use the following to update: ``` shell git checkout my-new-feature git fetch -a git pull --rebase upstream main git push --force-with-lease origin my-new-feature ``` ### Updating pull requests If your PR fails to pass CI or needs changes based on code review, you'll most likely want to squash these changes into existing commits. If your pull request contains a single commit or your changes are related to the most recent commit, you can simply amend the commit. ``` shell git add . git commit --amend git push --force-with-lease origin my-new-feature ``` If you need to squash changes into an earlier commit, you can use: ``` shell git add . git commit --fixup git rebase -i --autosquash main git push --force-with-lease origin my-new-feature ``` Be sure to add a comment to the PR indicating your new changes are ready to review, as GitHub does not generate a notification when you git push. ### Formatting Commit Messages We follow the conventions on [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/). Be sure to include any related GitHub issue references in the commit message. See [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) for referencing issues and commits. ## Reporting Bugs and Creating Issues When opening a new issue, try to roughly follow the commit message format conventions above. tests000755001750001750 014612756433 21434 5ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suitebasic.json100644001750001750 2034414612756433 23573 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests{ "tests": [ { "name": "root", "selector": "$", "document": [ "first", "second" ], "result": [ [ "first", "second" ] ] }, { "name": "no leading whitespace", "selector": " $", "invalid_selector": true }, { "name": "no trailing whitespace", "selector": "$ ", "invalid_selector": true }, { "name": "name shorthand", "selector": "$.a", "document": { "a": "A", "b": "B" }, "result": [ "A" ] }, { "name": "name shorthand, extended unicode ☺", "selector": "$.☺", "document": { "☺": "A", "b": "B" }, "result": [ "A" ] }, { "name": "name shorthand, underscore", "selector": "$._", "document": { "_": "A", "_foo": "B" }, "result": [ "A" ] }, { "name": "name shorthand, symbol", "selector": "$.&", "invalid_selector": true }, { "name": "name shorthand, number", "selector": "$.1", "invalid_selector": true }, { "name": "name shorthand, absent data", "selector": "$.c", "document": { "a": "A", "b": "B" }, "result": [] }, { "name": "name shorthand, array data", "selector": "$.a", "document": [ "first", "second" ], "result": [] }, { "name": "wildcard shorthand, object data", "selector": "$.*", "document": { "a": "A", "b": "B" }, "results": [[ "A", "B" ],[ "B", "A" ]] }, { "name": "wildcard shorthand, array data", "selector": "$.*", "document": [ "first", "second" ], "result": [ "first", "second" ] }, { "name": "wildcard selector, array data", "selector": "$[*]", "document": [ "first", "second" ], "result": [ "first", "second" ] }, { "name": "wildcard shorthand, then name shorthand", "selector": "$.*.a", "document": { "x": { "a": "Ax", "b": "Bx" }, "y": { "a": "Ay", "b": "By" } }, "results": [[ "Ax", "Ay" ],[ "Ay", "Ax" ]] }, { "name": "multiple selectors", "selector": "$[0,2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 2 ] }, { "name": "multiple selectors, space instead of comma", "selector": "$[0 2]", "invalid_selector": true }, { "name": "multiple selectors, name and index, array data", "selector": "$['a',1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1 ] }, { "name": "multiple selectors, name and index, object data", "selector": "$['a',1]", "document": { "a": 1, "b": 2 }, "result": [ 1 ] }, { "name": "multiple selectors, index and slice", "selector": "$[1,5:7]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 5, 6 ] }, { "name": "multiple selectors, index and slice, overlapping", "selector": "$[1,0:3]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 0, 1, 2 ] }, { "name": "multiple selectors, duplicate index", "selector": "$[1,1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 1 ] }, { "name": "multiple selectors, wildcard and index", "selector": "$[*,1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1 ] }, { "name": "multiple selectors, wildcard and name", "selector": "$[*,'a']", "document": { "a": "A", "b": "B" }, "results": [ [ "A", "B", "A" ], [ "B", "A", "A" ] ] }, { "name": "multiple selectors, wildcard and slice", "selector": "$[*,0:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 ] }, { "name": "multiple selectors, multiple wildcards", "selector": "$[*,*]", "document": [ 0, 1, 2 ], "result": [ 0, 1, 2, 0, 1, 2 ] }, { "name": "empty segment", "selector": "$[]", "invalid_selector": true }, { "name": "descendant segment, index", "selector" : "$..[1]", "document" : {"o": [0, 1, [2, 3]]}, "result": [ 1, 3 ] }, { "name": "descendant segment, name shorthand", "selector" : "$..a", "document" : {"o": [{"a": "b"}, {"a":"c"}]}, "result": [ "b", "c" ] }, { "name": "descendant segment, wildcard shorthand, array data", "selector" : "$..*", "document" : [0, 1], "result": [ 0, 1 ] }, { "name": "descendant segment, wildcard selector, array data", "selector" : "$..[*]", "document" : [0, 1], "result": [ 0, 1 ] }, { "name": "descendant segment, wildcard selector, nested arrays", "selector" : "$..[*]", "document" : [[[1]],[2]], "results": [ [[[1]],[2],[1],1,2], [[[1]],[2],[1],2,1] ] }, { "name": "descendant segment, wildcard selector, nested objects", "selector" : "$..[*]", "document" : {"a": {"c": {"e": 1}}, "b": {"d": 2}}, "results": [ [{"c": {"e": 1}}, {"d": 2}, {"e": 1}, 1, 2], [{"c": {"e": 1}}, {"d": 2}, {"e": 1}, 2, 1], [{"c": {"e": 1}}, {"d": 2}, 2, {"e": 1}, 1], [{"d": 2}, {"c": {"e": 1}}, {"e": 1}, 1, 2], [{"d": 2}, {"c": {"e": 1}}, {"e": 1}, 2, 1], [{"d": 2}, {"c": {"e": 1}}, 2, {"e": 1}, 1] ] }, { "name": "descendant segment, wildcard shorthand, object data", "selector" : "$..*", "document" : {"a": "b"}, "result": [ "b" ] }, { "name": "descendant segment, wildcard shorthand, nested data", "selector" : "$..*", "document" : { "o": [{"a": "b"}] }, "result": [ [ { "a" : "b" } ], { "a" : "b" }, "b" ] }, { "name": "descendant segment, multiple selectors", "selector" : "$..['a','d']", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}], "result": [ "b", "e", "c", "f" ] }, { "name": "descendant segment, object traversal, multiple selectors", "selector" : "$..['a','d']", "document" : {"x": {"a": "b", "d": "e"}, "y": {"a":"c", "d": "f"}}, "results": [[ "b", "e", "c", "f" ],[ "c", "f", "b", "e" ]] }, { "name": "bald descendant segment", "selector": "$..", "invalid_selector": true } ] } filter.json100644001750001750 6172714612756433 24011 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests{ "tests": [ { "name": "existence, without segments", "selector": "$[?@]", "document": {"a": 1, "b": null}, "results": [ [1, null], [null, 1] ] }, { "name": "existence", "selector" : "$[?@.a]", "document" : [{"a": "b", "d": "e"}, {"b":"c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "existence, present with null", "selector" : "$[?@.a]", "document" : [{"a": null, "d": "e"}, {"b":"c", "d": "f"}], "result": [ {"a": null, "d": "e"} ] }, { "name": "equals string, single quotes", "selector" : "$[?@.a=='b']", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "equals numeric string, single quotes", "selector" : "$[?@.a=='1']", "document" : [{"a": "1", "d": "e"}, {"a":1, "d": "f"}], "result": [ {"a": "1", "d": "e"} ] }, { "name": "equals string, double quotes", "selector" : "$[?@.a==\"b\"]", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "equals numeric string, double quotes", "selector" : "$[?@.a==\"1\"]", "document" : [{"a": "1", "d": "e"}, {"a":1, "d": "f"}], "result": [ {"a": "1", "d": "e"} ] }, { "name": "equals number", "selector" : "$[?@.a==1]", "document" : [{"a": 1, "d": "e"}, {"a":"c", "d": "f"}, {"a":2, "d": "f"}, {"a":"1", "d": "f"}], "result": [ {"a": 1, "d": "e"} ] }, { "name": "equals null", "selector" : "$[?@.a==null]", "document" : [{"a": null, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": null, "d": "e"} ] }, { "name": "equals null, absent from data", "selector" : "$[?@.a==null]", "document" : [{"d": "e"}, {"a":"c", "d": "f"}], "result": [ ] }, { "name": "equals true", "selector" : "$[?@.a==true]", "document" : [{"a": true, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": true, "d": "e"} ] }, { "name": "equals false", "selector" : "$[?@.a==false]", "document" : [{"a": false, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": false, "d": "e"} ] }, { "name": "equals self", "selector" : "$[?@==@]", "document" : [1, null, true, {"a": "b"}, [false]], "result": [ 1, null, true, {"a": "b"}, [false] ] }, { "name": "deep equality, arrays", "selector" : "$[?@.a==@.b]", "document" : [ {"a": false, "b": [1, 2]}, {"a": [[1, [2]]], "b": [[1, [2]]]}, {"a": [[1, [2]]], "b": [[[2], 1]]}, {"a": [[1, [2]]], "b": [[1, 2]]} ], "result": [ {"a": [[1, [2]]], "b": [[1, [2]]]} ] }, { "name": "deep equality, objects", "selector" : "$[?@.a==@.b]", "document" : [ {"a": false, "b": {"x": 1, "y": {"z": 1}}}, {"a": {"x": 1, "y": {"z": 1}}, "b": {"x": 1, "y": {"z": 1}}}, {"a": {"x": 1, "y": {"z": 1}}, "b": {"y": {"z": 1}, "x": 1}}, {"a": {"x": 1, "y": {"z": 1}}, "b": {"x": 1}}, {"a": {"x": 1, "y": {"z": 1}}, "b": {"x": 1, "y": {"z": 2}}} ], "result": [ {"a": {"x": 1, "y": {"z": 1}}, "b": {"x": 1, "y": {"z": 1}}}, {"a": {"x": 1, "y": {"z": 1}}, "b": {"y": {"z": 1}, "x": 1}} ] }, { "name": "not-equals string, single quotes", "selector" : "$[?@.a!='b']", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a":"c", "d": "f"} ] }, { "name": "not-equals numeric string, single quotes", "selector" : "$[?@.a!='1']", "document" : [{"a": "1", "d": "e"}, {"a":1, "d": "f"}], "result": [ {"a":1, "d": "f"} ] }, { "name": "not-equals string, single quotes, different type", "selector" : "$[?@.a!='b']", "document" : [{"a": "b", "d": "e"}, {"a":1, "d": "f"}], "result": [ {"a":1, "d": "f"} ] }, { "name": "not-equals string, double quotes", "selector" : "$[?@.a!=\"b\"]", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a":"c", "d": "f"} ] }, { "name": "not-equals numeric string, double quotes", "selector" : "$[?@.a!=\"1\"]", "document" : [{"a": "1", "d": "e"}, {"a":1, "d": "f"}], "result": [ {"a":1, "d": "f"} ] }, { "name": "not-equals string, double quotes, different types", "selector" : "$[?@.a!=\"b\"]", "document" : [{"a": "b", "d": "e"}, {"a":1, "d": "f"}], "result": [ {"a":1, "d": "f"} ] }, { "name": "not-equals number", "selector" : "$[?@.a!=1]", "document" : [{"a": 1, "d": "e"}, {"a":2, "d": "f"}, {"a":"1", "d": "f"}], "result": [ {"a":2, "d": "f"}, {"a":"1", "d": "f"} ] }, { "name": "not-equals number, different types", "selector" : "$[?@.a!=1]", "document" : [{"a": 1, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a":"c", "d": "f"} ] }, { "name": "not-equals null", "selector" : "$[?@.a!=null]", "document" : [{"a": null, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a":"c", "d": "f"} ] }, { "name": "not-equals null, absent from data", "selector" : "$[?@.a!=null]", "document" : [{"d": "e"}, {"a":"c", "d": "f"}], "result": [ {"d": "e"}, {"a":"c", "d": "f"} ] }, { "name": "not-equals true", "selector" : "$[?@.a!=true]", "document" : [{"a": true, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a":"c", "d": "f"} ] }, { "name": "not-equals false", "selector" : "$[?@.a!=false]", "document" : [{"a": false, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a":"c", "d": "f"} ] }, { "name": "less than string, single quotes", "selector" : "$[?@.a<'c']", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "less than string, double quotes", "selector" : "$[?@.a<\"c\"]", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "less than number", "selector" : "$[?@.a<10]", "document" : [{"a": 1, "d": "e"}, {"a": 10, "d": "e"}, {"a":"c", "d": "f"}, {"a":20, "d": "f"}], "result": [ {"a": 1, "d": "e"} ] }, { "name": "less than null", "selector" : "$[?@.a'c']", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}, {"a":"d", "d": "f"}], "result": [ {"a":"d", "d": "f"} ] }, { "name": "greater than string, double quotes", "selector" : "$[?@.a>\"c\"]", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}, {"a":"d", "d": "f"}], "result": [ {"a":"d", "d": "f"} ] }, { "name": "greater than number", "selector" : "$[?@.a>10]", "document" : [{"a": 1, "d": "e"}, {"a": 10, "d": "e"}, {"a":"c", "d": "f"}, {"a":20, "d": "f"}], "result": [ {"a":20, "d": "f"} ] }, { "name": "greater than null", "selector" : "$[?@.a>null]", "document" : [{"a": null, "d": "e"}, {"a":"c", "d": "f"}], "result": [ ] }, { "name": "greater than true", "selector" : "$[?@.a>true]", "document" : [{"a": true, "d": "e"}, {"a":"c", "d": "f"}], "result": [ ] }, { "name": "greater than false", "selector" : "$[?@.a>false]", "document" : [{"a": false, "d": "e"}, {"a":"c", "d": "f"}], "result": [ ] }, { "name": "greater than or equal to string, single quotes", "selector" : "$[?@.a>='c']", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}, {"a":"d", "d": "f"}], "result": [ {"a":"c", "d": "f"}, {"a":"d", "d": "f"} ] }, { "name": "greater than or equal to string, double quotes", "selector" : "$[?@.a>=\"c\"]", "document" : [{"a": "b", "d": "e"}, {"a":"c", "d": "f"}, {"a":"d", "d": "f"}], "result": [ {"a":"c", "d": "f"}, {"a":"d", "d": "f"} ] }, { "name": "greater than or equal to number", "selector" : "$[?@.a>=10]", "document" : [{"a": 1, "d": "e"}, {"a": 10, "d": "e"}, {"a":"c", "d": "f"}, {"a":20, "d": "f"}], "result": [ {"a": 10, "d": "e"}, {"a":20, "d": "f"} ] }, { "name": "greater than or equal to null", "selector" : "$[?@.a>=null]", "document" : [{"a": null, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": null, "d": "e"} ] }, { "name": "greater than or equal to true", "selector" : "$[?@.a>=true]", "document" : [{"a": true, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": true, "d": "e"} ] }, { "name": "greater than or equal to false", "selector" : "$[?@.a>=false]", "document" : [{"a": false, "d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a": false, "d": "e"} ] }, { "name": "exists and not-equals null, absent from data", "selector" : "$[?@.a&&@.a!=null]", "document" : [{"d": "e"}, {"a":"c", "d": "f"}], "result": [ {"a":"c", "d": "f"} ] }, { "name": "exists and exists, data false", "selector" : "$[?@.a&&@.b]", "document" : [{"a": false, "b": false}, {"b": false}, {"c": false}], "result": [ {"a": false, "b": false} ] }, { "name": "exists or exists, data false", "selector" : "$[?@.a||@.b]", "document" : [{"a": false, "b": false}, {"b": false}, {"c": false}], "result": [ {"a": false, "b": false}, {"b": false} ] }, { "name": "and", "selector" : "$[?@.a>0&&@.a<10]", "document" : [{"a": -10, "d": "e"}, {"a":5, "d": "f"}, {"a":20, "d": "f"}], "result": [ {"a":5, "d": "f"} ] }, { "name": "or", "selector" : "$[?@.a=='b'||@.a=='d']", "document" : [{"a": "a", "d": "e"}, {"a":"b", "d": "f"}, {"a":"c", "d": "f"}, {"a":"d", "d": "f"}], "result": [ {"a":"b", "d": "f"}, {"a":"d", "d": "f"} ] }, { "name": "not expression", "selector" : "$[?!(@.a=='b')]", "document" : [{"a": "a", "d": "e"}, {"a":"b", "d": "f"}, {"a":"d", "d": "f"}], "result": [ {"a": "a", "d": "e"}, {"a": "d", "d": "f"} ] }, { "name": "not exists", "selector" : "$[?!@.a]", "document" : [{"a": "a", "d": "e"}, {"d": "f"}, {"a":"d", "d": "f"}], "result": [ {"d": "f"} ] }, { "name": "not exists, data null", "selector" : "$[?!@.a]", "document" : [{"a": null, "d": "e"}, {"d": "f"}, {"a":"d", "d": "f"}], "result": [ {"d": "f"} ] }, { "name": "non-singular existence, wildcard", "selector" : "$[?@.*]", "document" : [1, [], [2], {}, {"a": 3}], "result": [ [2], {"a": 3} ] }, { "name": "non-singular existence, multiple", "selector" : "$[?@[0, 0, 'a']]", "document" : [1, [], [2], [2, 3], {"a": 3}, {"b": 4}, {"a": 3, "b": 4}], "result": [ [2], [2, 3], {"a": 3}, {"a": 3, "b": 4} ] }, { "name": "non-singular existence, slice", "selector" : "$[?@[0:2]]", "document" : [1, [], [2], [2, 3, 4], {}, {"a": 3}], "result": [ [2], [2, 3, 4] ] }, { "name": "non-singular existence, negated", "selector" : "$[?!@.*]", "document" : [1, [], [2], {}, {"a": 3}], "result": [ 1, [], {} ] }, { "name": "non-singular query in comparison, slice", "selector" : "$[?@[0:0]==0]", "invalid_selector": true }, { "name": "non-singular query in comparison, all children", "selector" : "$[?@[*]==0]", "invalid_selector": true }, { "name": "non-singular query in comparison, descendants", "selector" : "$[?@..a==0]", "invalid_selector": true }, { "name": "non-singular query in comparison, combined", "selector" : "$[?@.a[*].a==0]", "invalid_selector": true }, { "name": "nested", "selector": "$[?@[?@>1]]", "document": [[0], [0, 1], [0, 1, 2], [42]], "result": [ [0, 1, 2], [42] ] }, { "name": "name segment on primitive, selects nothing", "selector": "$[?@.a == 1]", "document": {"a": 1}, "result": [] }, { "name": "name segment on array, selects nothing", "selector": "$[?@['0'] == 5]", "document": [[5, 6]], "result": [] }, { "name": "index segment on object, selects nothing", "selector": "$[?@[0] == 5]", "document": [{"0": 5}], "result": [] }, { "name": "relative non-singular query, index, equal", "selector": "$[?(@[0, 0]==42)]", "invalid_selector": true }, { "name": "relative non-singular query, index, not equal", "selector": "$[?(@[0, 0]!=42)]", "invalid_selector": true }, { "name": "relative non-singular query, index, less-or-equal", "selector": "$[?(@[0, 0]<=42)]", "invalid_selector": true }, { "name": "relative non-singular query, name, equal", "selector": "$[?(@['a', 'a']==42)]", "invalid_selector": true }, { "name": "relative non-singular query, name, not equal", "selector": "$[?(@['a', 'a']!=42)]", "invalid_selector": true }, { "name": "relative non-singular query, name, less-or-equal", "selector": "$[?(@['a', 'a']<=42)]", "invalid_selector": true }, { "name": "relative non-singular query, combined, equal", "selector": "$[?(@[0, '0']==42)]", "invalid_selector": true }, { "name": "relative non-singular query, combined, not equal", "selector": "$[?(@[0, '0']!=42)]", "invalid_selector": true }, { "name": "relative non-singular query, combined, less-or-equal", "selector": "$[?(@[0, '0']<=42)]", "invalid_selector": true }, { "name": "relative non-singular query, wildcard, equal", "selector": "$[?(@.*==42)]", "invalid_selector": true }, { "name": "relative non-singular query, wildcard, not equal", "selector": "$[?(@.*!=42)]", "invalid_selector": true }, { "name": "relative non-singular query, wildcard, less-or-equal", "selector": "$[?(@.*<=42)]", "invalid_selector": true }, { "name": "relative non-singular query, slice, equal", "selector": "$[?(@[0:0]==42)]", "invalid_selector": true }, { "name": "relative non-singular query, slice, not equal", "selector": "$[?(@[0:0]!=42)]", "invalid_selector": true }, { "name": "relative non-singular query, slice, less-or-equal", "selector": "$[?(@[0:0]<=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, index, equal", "selector": "$[?($[0, 0]==42)]", "invalid_selector": true }, { "name": "absolute non-singular query, index, not equal", "selector": "$[?($[0, 0]!=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, index, less-or-equal", "selector": "$[?($[0, 0]<=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, name, equal", "selector": "$[?($['a', 'a']==42)]", "invalid_selector": true }, { "name": "absolute non-singular query, name, not equal", "selector": "$[?($['a', 'a']!=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, name, less-or-equal", "selector": "$[?($['a', 'a']<=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, combined, equal", "selector": "$[?($[0, '0']==42)]", "invalid_selector": true }, { "name": "absolute non-singular query, combined, not equal", "selector": "$[?($[0, '0']!=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, combined, less-or-equal", "selector": "$[?($[0, '0']<=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, wildcard, equal", "selector": "$[?($.*==42)]", "invalid_selector": true }, { "name": "absolute non-singular query, wildcard, not equal", "selector": "$[?($.*!=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, wildcard, less-or-equal", "selector": "$[?($.*<=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, slice, equal", "selector": "$[?($[0:0]==42)]", "invalid_selector": true }, { "name": "absolute non-singular query, slice, not equal", "selector": "$[?($[0:0]!=42)]", "invalid_selector": true }, { "name": "absolute non-singular query, slice, less-or-equal", "selector": "$[?($[0:0]<=42)]", "invalid_selector": true }, { "name": "multiple selectors", "selector" : "$[?@.a,?@.b]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"}, {"b": "c", "d": "f"} ] }, { "name": "multiple selectors, comparison", "selector" : "$[?@.a=='b',?@.b=='x']", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "multiple selectors, overlapping", "selector" : "$[?@.a,?@.d]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"}, {"a": "b", "d": "e"}, {"b": "c", "d": "f"} ] }, { "name": "multiple selectors, filter and index", "selector" : "$[?@.a,1]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"}, {"b": "c", "d": "f"} ] }, { "name": "multiple selectors, filter and wildcard", "selector" : "$[?@.a,*]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"}, {"a": "b", "d": "e"}, {"b": "c", "d": "f"} ] }, { "name": "multiple selectors, filter and slice", "selector" : "$[?@.a,1:]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}, {"g": "h"}], "result": [ {"a": "b", "d": "e"}, {"b": "c", "d": "f"}, {"g": "h"} ] }, { "name": "multiple selectors, comparison filter, index and slice", "selector" : "$[1, ?@.a=='b', 1:]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"b": "c", "d": "f"}, {"a": "b", "d": "e"}, {"b": "c", "d": "f"} ] }, { "name": "equals number, zero and negative zero", "selector" : "$[?@.a==-0]", "document" : [{"a": 0, "d": "e"}, {"a":0.1, "d": "f"}, {"a":"0", "d": "g"}], "result": [ {"a": 0, "d": "e"} ] }, { "name": "equals number, with and without decimal fraction", "selector" : "$[?@.a==1.0]", "document" : [{"a": 1, "d": "e"}, {"a":2, "d": "f"}, {"a":"1", "d": "g"}], "result": [ {"a": 1, "d": "e"} ] }, { "name": "equals number, exponent", "selector" : "$[?@.a==1e2]", "document" : [{"a": 100, "d": "e"}, {"a":100.1, "d": "f"}, {"a":"100", "d": "g"}], "result": [ {"a": 100, "d": "e"} ] }, { "name": "equals number, positive exponent", "selector" : "$[?@.a==1e+2]", "document" : [{"a": 100, "d": "e"}, {"a":100.1, "d": "f"}, {"a":"100", "d": "g"}], "result": [ {"a": 100, "d": "e"} ] }, { "name": "equals number, negative exponent", "selector" : "$[?@.a==1e-2]", "document" : [{"a": 0.01, "d": "e"}, {"a":0.02, "d": "f"}, {"a":"0.01", "d": "g"}], "result": [ {"a": 0.01, "d": "e"} ] }, { "name": "equals number, decimal fraction", "selector" : "$[?@.a==1.1]", "document" : [{"a": 1.1, "d": "e"}, {"a":1.0, "d": "f"}, {"a":"1.1", "d": "g"}], "result": [ {"a": 1.1, "d": "e"} ] }, { "name": "equals number, decimal fraction, no fractional digit", "selector" : "$[?@.a==1.]", "invalid_selector": true }, { "name": "equals number, decimal fraction, exponent", "selector" : "$[?@.a==1.1e2]", "document" : [{"a": 110, "d": "e"}, {"a":110.1, "d": "f"}, {"a":"110", "d": "g"}], "result": [ {"a": 110, "d": "e"} ] }, { "name": "equals number, decimal fraction, positive exponent", "selector" : "$[?@.a==1.1e+2]", "document" : [{"a": 110, "d": "e"}, {"a":110.1, "d": "f"}, {"a":"110", "d": "g"}], "result": [ {"a": 110, "d": "e"} ] }, { "name": "equals number, decimal fraction, negative exponent", "selector" : "$[?@.a==1.1e-2]", "document" : [{"a": 0.011, "d": "e"}, {"a":0.012, "d": "f"}, {"a":"0.011", "d": "g"}], "result": [ {"a": 0.011, "d": "e"} ] }, { "name": "equals, special nothing", "selector" : "$.values[?length(@.a) == value($..c)]", "document" : { "c": "cd", "values": [ {"a": "ab"}, {"c": "d"}, {"a": null} ] }, "result": [ {"c": "d"}, {"a": null} ] }, { "name": "object data", "selector" : "$[?@<3]", "document" : { "a": 1, "b": 2, "c": 3 }, "results": [ [1, 2], [2, 1] ] }, { "name": "and binds more tightly than or", "selector" : "$[?@.a || @.b && @.b]", "document" : [{"a": 1}], "result": [ {"a": 1} ] }, { "name": "left to right evaluation", "selector" : "$[?@.b && @.b || @.a]", "document" : [{"a": 1}], "result": [ {"a": 1} ] }, { "name": "group terms, left", "selector" : "$[?(@.a || @.b) && @.a]", "document" : [{"a": 1}], "result": [ {"a": 1} ] }, { "name": "group terms, right", "selector" : "$[?@.a && (@.b || @.a)]", "document" : [{"a": 1}], "result": [ {"a": 1} ] }, { "name": "group terms, or before and", "selector" : "$[?(@.a || @.b) && @.b]", "document" : [{"a": 1}], "result": [] } ] } CODE_OF_CONDUCT.md100644001750001750 646714612756433 23246 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in jsonpath-compliance-test-suite project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at oss-coc@vmware.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq name_selector.json100644001750001750 3541414612756433 25336 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests{ "tests": [ { "name": "double quotes", "selector": "$[\"a\"]", "document": { "a": "A", "b": "B" }, "result": [ "A" ] }, { "name": "double quotes, absent data", "selector": "$[\"c\"]", "document": { "a": "A", "b": "B" }, "result": [] }, { "name": "double quotes, array data", "selector": "$[\"a\"]", "document": [ "first", "second" ], "result": [] }, { "name": "double quotes, embedded U+0000", "selector": "$[\"\u0000\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0001", "selector": "$[\"\u0001\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0002", "selector": "$[\"\u0002\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0003", "selector": "$[\"\u0003\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0004", "selector": "$[\"\u0004\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0005", "selector": "$[\"\u0005\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0006", "selector": "$[\"\u0006\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0007", "selector": "$[\"\u0007\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0008", "selector": "$[\"\u0008\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0009", "selector": "$[\"\u0009\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+000A", "selector": "$[\"\u000A\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+000B", "selector": "$[\"\u000B\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+000C", "selector": "$[\"\u000C\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+000D", "selector": "$[\"\u000D\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+000E", "selector": "$[\"\u000E\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+000F", "selector": "$[\"\u000F\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0010", "selector": "$[\"\u0010\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0011", "selector": "$[\"\u0011\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0012", "selector": "$[\"\u0012\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0013", "selector": "$[\"\u0013\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0014", "selector": "$[\"\u0014\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0015", "selector": "$[\"\u0015\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0016", "selector": "$[\"\u0016\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0017", "selector": "$[\"\u0017\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0018", "selector": "$[\"\u0018\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0019", "selector": "$[\"\u0019\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+001A", "selector": "$[\"\u001A\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+001B", "selector": "$[\"\u001B\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+001C", "selector": "$[\"\u001C\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+001D", "selector": "$[\"\u001D\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+001E", "selector": "$[\"\u001E\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+001F", "selector": "$[\"\u001F\"]", "invalid_selector": true }, { "name": "double quotes, embedded U+0020", "selector": "$[\"\u0020\"]", "document": { "\u0020": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped double quote", "selector": "$[\"\\\"\"]", "document": { "\"": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped reverse solidus", "selector": "$[\"\\\\\"]", "document": { "\\": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped solidus", "selector": "$[\"\\/\"]", "document": { "/": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped backspace", "selector": "$[\"\\b\"]", "document": { "\u0008": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped form feed", "selector": "$[\"\\f\"]", "document": { "\u000C": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped line feed", "selector": "$[\"\\n\"]", "document": { "\u000A": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped carriage return", "selector": "$[\"\\r\"]", "document": { "\u000D": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped tab", "selector": "$[\"\\t\"]", "document": { "\u0009": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped ☺, upper case hex", "selector": "$[\"\\u263A\"]", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "double quotes, escaped ☺, lower case hex", "selector": "$[\"\\u263a\"]", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "double quotes, surrogate pair 𝄞", "selector": "$[\"\\uD834\\uDD1E\"]", "document": { "𝄞": "A" }, "result": [ "A" ] }, { "name": "double quotes, surrogate pair 😀", "selector": "$[\"\\uD83D\\uDE00\"]", "document": { "😀": "A" }, "result": [ "A" ] }, { "name": "double quotes, invalid escaped single quote", "selector": "$[\"\\'\"]", "invalid_selector": true }, { "name": "double quotes, embedded double quote", "selector": "$[\"\"\"]", "invalid_selector": true }, { "name": "double quotes, incomplete escape", "selector": "$[\"\\\"]", "invalid_selector": true }, { "name": "single quotes", "selector": "$['a']", "document": { "a": "A", "b": "B" }, "result": [ "A" ] }, { "name": "single quotes, absent data", "selector": "$['c']", "document": { "a": "A", "b": "B" }, "result": [] }, { "name": "single quotes, array data", "selector": "$['a']", "document": [ "first", "second" ], "result": [] }, { "name": "single quotes, embedded U+0000", "selector": "$['\u0000']", "invalid_selector": true }, { "name": "single quotes, embedded U+0001", "selector": "$['\u0001']", "invalid_selector": true }, { "name": "single quotes, embedded U+0002", "selector": "$['\u0002']", "invalid_selector": true }, { "name": "single quotes, embedded U+0003", "selector": "$['\u0003']", "invalid_selector": true }, { "name": "single quotes, embedded U+0004", "selector": "$['\u0004']", "invalid_selector": true }, { "name": "single quotes, embedded U+0005", "selector": "$['\u0005']", "invalid_selector": true }, { "name": "single quotes, embedded U+0006", "selector": "$['\u0006']", "invalid_selector": true }, { "name": "single quotes, embedded U+0007", "selector": "$['\u0007']", "invalid_selector": true }, { "name": "single quotes, embedded U+0008", "selector": "$['\u0008']", "invalid_selector": true }, { "name": "single quotes, embedded U+0009", "selector": "$['\u0009']", "invalid_selector": true }, { "name": "single quotes, embedded U+000A", "selector": "$['\u000A']", "invalid_selector": true }, { "name": "single quotes, embedded U+000B", "selector": "$['\u000B']", "invalid_selector": true }, { "name": "single quotes, embedded U+000C", "selector": "$['\u000C']", "invalid_selector": true }, { "name": "single quotes, embedded U+000D", "selector": "$['\u000D']", "invalid_selector": true }, { "name": "single quotes, embedded U+000E", "selector": "$['\u000E']", "invalid_selector": true }, { "name": "single quotes, embedded U+000F", "selector": "$['\u000F']", "invalid_selector": true }, { "name": "single quotes, embedded U+0010", "selector": "$['\u0010']", "invalid_selector": true }, { "name": "single quotes, embedded U+0011", "selector": "$['\u0011']", "invalid_selector": true }, { "name": "single quotes, embedded U+0012", "selector": "$['\u0012']", "invalid_selector": true }, { "name": "single quotes, embedded U+0013", "selector": "$['\u0013']", "invalid_selector": true }, { "name": "single quotes, embedded U+0014", "selector": "$['\u0014']", "invalid_selector": true }, { "name": "single quotes, embedded U+0015", "selector": "$['\u0015']", "invalid_selector": true }, { "name": "single quotes, embedded U+0016", "selector": "$['\u0016']", "invalid_selector": true }, { "name": "single quotes, embedded U+0017", "selector": "$['\u0017']", "invalid_selector": true }, { "name": "single quotes, embedded U+0018", "selector": "$['\u0018']", "invalid_selector": true }, { "name": "single quotes, embedded U+0019", "selector": "$['\u0019']", "invalid_selector": true }, { "name": "single quotes, embedded U+001A", "selector": "$['\u001A']", "invalid_selector": true }, { "name": "single quotes, embedded U+001B", "selector": "$['\u001B']", "invalid_selector": true }, { "name": "single quotes, embedded U+001C", "selector": "$['\u001C']", "invalid_selector": true }, { "name": "single quotes, embedded U+001D", "selector": "$['\u001D']", "invalid_selector": true }, { "name": "single quotes, embedded U+001E", "selector": "$['\u001E']", "invalid_selector": true }, { "name": "single quotes, embedded U+001F", "selector": "$['\u001F']", "invalid_selector": true }, { "name": "single quotes, embedded U+0020", "selector": "$['\u0020']", "document": { "\u0020": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped single quote", "selector": "$['\\'']", "document": { "'": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped reverse solidus", "selector": "$['\\\\']", "document": { "\\": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped solidus", "selector": "$['\\/']", "document": { "/": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped backspace", "selector": "$['\\b']", "document": { "\u0008": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped form feed", "selector": "$['\\f']", "document": { "\u000C": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped line feed", "selector": "$['\\n']", "document": { "\u000A": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped carriage return", "selector": "$['\\r']", "document": { "\u000D": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped tab", "selector": "$['\\t']", "document": { "\u0009": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped ☺, upper case hex", "selector": "$['\\u263A']", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "single quotes, escaped ☺, lower case hex", "selector": "$['\\u263a']", "document": { "☺": "A" }, "result": [ "A" ] }, { "name": "single quotes, surrogate pair 𝄞", "selector": "$['\\uD834\\uDD1E']", "document": { "𝄞": "A" }, "result": [ "A" ] }, { "name": "single quotes, surrogate pair 😀", "selector": "$['\\uD83D\\uDE00']", "document": { "😀": "A" }, "result": [ "A" ] }, { "name": "single quotes, invalid escaped double quote", "selector": "$['\\\"']", "invalid_selector": true }, { "name": "single quotes, embedded single quote", "selector": "$[''']", "invalid_selector": true }, { "name": "single quotes, incomplete escape", "selector": "$['\\']", "invalid_selector": true }, { "name": "double quotes, empty", "selector": "$[\"\"]", "document": { "a": "A", "b": "B", "": "C" }, "result": [ "C" ] }, { "name": "single quotes, empty", "selector": "$['']", "document": { "a": "A", "b": "B", "": "C" }, "result": [ "C" ] } ] } slice_selector.json100644001750001750 2326514612756433 25516 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests{ "tests": [ { "name": "slice selector", "selector": "$[1:3]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 2 ] }, { "name": "slice selector with step", "selector": "$[1:6:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 3, 5 ] }, { "name": "slice selector with everything omitted, short form", "selector": "$[:]", "document": [ 0, 1, 2, 3 ], "result": [ 0, 1, 2, 3 ] }, { "name": "slice selector with everything omitted, long form", "selector": "$[::]", "document": [ 0, 1, 2, 3 ], "result": [ 0, 1, 2, 3 ] }, { "name": "slice selector with start omitted", "selector": "$[:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1 ] }, { "name": "slice selector with start and end omitted", "selector": "$[::2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 2, 4, 6, 8 ] }, { "name": "negative step with default start and end", "selector": "$[::-1]", "document": [ 0, 1, 2, 3 ], "result": [ 3, 2, 1, 0 ] }, { "name": "negative step with default start", "selector": "$[:0:-1]", "document": [ 0, 1, 2, 3 ], "result": [ 3, 2, 1 ] }, { "name": "negative step with default end", "selector": "$[2::-1]", "document": [ 0, 1, 2, 3 ], "result": [ 2, 1, 0 ] }, { "name": "larger negative step", "selector": "$[::-2]", "document": [ 0, 1, 2, 3 ], "result": [ 3, 1 ] }, { "name": "negative range with default step", "selector": "$[-1:-3]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [] }, { "name": "negative range with negative step", "selector": "$[-1:-3:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8 ] }, { "name": "negative range with larger negative step", "selector": "$[-1:-6:-2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 7, 5 ] }, { "name": "larger negative range with larger negative step", "selector": "$[-1:-7:-2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 7, 5 ] }, { "name": "negative from, positive to", "selector": "$[-5:7]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 5, 6 ] }, { "name": "negative from", "selector": "$[-2:]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 8, 9 ] }, { "name": "positive from, negative to", "selector": "$[1:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1, 2, 3, 4, 5, 6, 7, 8 ] }, { "name": "negative from, positive to, negative step", "selector": "$[-1:1:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8, 7, 6, 5, 4, 3, 2 ] }, { "name": "positive from, negative to, negative step", "selector": "$[7:-5:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 7, 6 ] }, { "name": "too many colons", "selector": "$[1:2:3:4]", "invalid_selector": true }, { "name": "non-integer array index", "selector": "$[1:2:a]", "invalid_selector": true }, { "name": "zero step", "selector": "$[1:2:0]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [] }, { "name": "empty range", "selector": "$[2:2]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [] }, { "name": "slice selector with everything omitted with empty array", "selector": "$[:]", "document": [], "result": [] }, { "name": "negative step with empty array", "selector": "$[::-1]", "document": [], "result": [] }, { "name": "maximal range with positive step", "selector": "$[0:10]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] }, { "name": "maximal range with negative step", "selector": "$[9:0:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8, 7, 6, 5, 4, 3, 2, 1 ] }, { "name": "excessively large to value", "selector": "$[2:113667776004]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 2, 3, 4, 5, 6, 7, 8, 9 ] }, { "name": "excessively small from value", "selector": "$[-113667776004:1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 0 ] }, { "name": "excessively large from value with negative step", "selector": "$[113667776004:0:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9, 8, 7, 6, 5, 4, 3, 2, 1 ] }, { "name": "excessively small to value with negative step", "selector": "$[3:-113667776004:-1]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 3, 2, 1, 0 ] }, { "name": "excessively large step", "selector": "$[1:10:113667776004]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 1 ] }, { "name": "excessively small step", "selector": "$[-1:-10:-113667776004]", "document": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "result": [ 9 ] }, { "name": "overflowing to value", "selector": "$[2:231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true }, { "name": "underflowing from value", "selector": "$[-231584178474632390847141970017375815706539969331281128078915168015826259279872:1]", "invalid_selector": true }, { "name": "overflowing from value with negative step", "selector": "$[231584178474632390847141970017375815706539969331281128078915168015826259279872:0:-1]", "invalid_selector": true }, { "name": "underflowing to value with negative step", "selector": "$[3:-231584178474632390847141970017375815706539969331281128078915168015826259279872:-1]", "invalid_selector": true }, { "name": "overflowing step", "selector": "$[1:10:231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true }, { "name": "underflowing step", "selector": "$[-1:-10:-231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true } ] } index_selector.json100644001750001750 335314612756433 25502 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests{ "tests": [ { "name": "first element", "selector": "$[0]", "document": [ "first", "second" ], "result": [ "first" ] }, { "name": "second element", "selector": "$[1]", "document": [ "first", "second" ], "result": [ "second" ] }, { "name": "out of bound", "selector": "$[2]", "document": [ "first", "second" ], "result": [] }, { "name": "overflowing index", "selector": "$[231584178474632390847141970017375815706539969331281128078915168015826259279872]", "invalid_selector": true }, { "name": "not actually an index, overflowing index leads into general text", "selector": "$[231584178474632390847141970017375815706539969331281128078915168SomeRandomText]", "invalid_selector": true }, { "name": "negative", "selector": "$[-1]", "document": [ "first", "second" ], "result": [ "second" ] }, { "name": "more negative", "selector": "$[-2]", "document": [ "first", "second" ], "result": [ "first" ] }, { "name": "negative out of bound", "selector": "$[-3]", "document": [ "first", "second" ], "result": [] }, { "name": "on object", "selector": "$[0]", "document": { "foo": 1 }, "result": [] }, { "name": "leading 0", "selector": "$[01]", "invalid_selector": true }, { "name": "leading -0", "selector": "$[-01]", "invalid_selector": true } ] } functions000755001750001750 014612756433 23444 5ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/testscount.json100644001750001750 456614612756433 25642 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/functions{ "tests": [ { "name": "count function", "selector": "$[?count(@..*)>2]", "document": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ], "result": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" } ] }, { "name": "single-node arg", "selector": "$[?count(@.a)>1]", "document": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ], "result": [] }, { "name": "multiple-selector arg", "selector": "$[?count(@['a','d'])>1]", "document": [ { "a": [ 1, 2, 3 ] }, { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ], "result": [ { "a": [ 1 ], "d": "f" }, { "a": 1, "d": "f" } ] }, { "name": "non-query arg, number", "selector": "$[?count(1)>2]", "invalid_selector": true }, { "name": "non-query arg, string", "selector": "$[?count('string')>2]", "invalid_selector": true }, { "name": "non-query arg, true", "selector": "$[?count(true)>2]", "invalid_selector": true }, { "name": "non-query arg, false", "selector": "$[?count(false)>2]", "invalid_selector": true }, { "name": "non-query arg, null", "selector": "$[?count(null)>2]", "invalid_selector": true }, { "name": "result must be compared", "selector": "$[?count(@..*)]", "invalid_selector": true }, { "name": "no params", "selector": "$[?count()==1]", "invalid_selector": true }, { "name": "too many params", "selector": "$[?count(@.a,@.b)==1]", "invalid_selector": true } ] } value.json100644001750001750 132014612756433 25607 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/functions{ "tests": [ { "name": "single-value nodelist", "selector" : "$[?value(@.*)==4]", "document" : [[4], {"foo": 4}, [5], {"foo": 5}, 4], "result": [[4], {"foo": 4}] }, { "name": "multi-value nodelist", "selector" : "$[?value(@.*)==4]", "document" : [[4,4], {"foo": 4, "bar": 4}], "result": [] }, { "name": "too few params", "selector" : "$[?value()==4]", "invalid_selector": true }, { "name": "too many params", "selector" : "$[?value(@.a,@.b)==4]", "invalid_selector": true }, { "name": "result must be compared", "selector" : "$[?value(@.a)]", "invalid_selector": true } ] } match.json100644001750001750 523714612756433 25602 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/functions{ "tests": [ { "name": "found match", "selector" : "$[?match(@.a, 'a.*')]", "document" : [{"a": "ab"}], "result": [ {"a":"ab"} ] }, { "name": "double quotes", "selector" : "$[?match(@.a, \"a.*\")]", "document" : [{"a": "ab"}], "result": [ {"a":"ab"} ] }, { "name": "regex from the document", "selector" : "$.values[?match(@, $.regex)]", "document" : {"regex": "b.?b", "values": ["abc", "bcd", "bab", "bba", "bbab", "b", true, [], {}]}, "result": ["bab"] }, { "name": "don't select match", "selector" : "$[?!match(@.a, 'a.*')]", "document" : [{"a": "ab"}], "result": [ ] }, { "name": "not a match", "selector" : "$[?match(@.a, 'a.*')]", "document" : [{"a": "bc"}], "result": [] }, { "name": "select non-match", "selector" : "$[?!match(@.a, 'a.*')]", "document" : [{"a": "bc"}], "result": [{"a": "bc"}] }, { "name": "non-string first arg", "selector" : "$[?match(1, 'a.*')]", "document" : [{"a": "bc"}], "result": [] }, { "name": "non-string second arg", "selector" : "$[?match(@.a, 1)]", "document" : [{"a": "bc"}], "result": [] }, { "name": "filter, match function, unicode char class, uppercase", "selector": "$[?match(@, '\\\\p{Lu}')]", "document": ["ж", "Ж", "1", "жЖ", true, [], {}], "result": ["Ж"] }, { "name": "filter, match function, unicode char class negated, uppercase", "selector": "$[?match(@, '\\\\P{Lu}')]", "document": ["ж", "Ж", "1", true, [], {}], "result": ["ж", "1"] }, { "name": "filter, match function, unicode, surrogate pair", "selector": "$[?match(@, 'a.b')]", "document": ["a\uD800\uDD01b", "ab", "1", true, [], {}], "result": ["a\uD800\uDD01b"] }, { "name": "result cannot be compared", "selector" : "$[?match(@.a, 'a.*')==true]", "invalid_selector": true }, { "name": "too few params", "selector" : "$[?match(@.a)==1]", "invalid_selector": true }, { "name": "too many params", "selector" : "$[?match(@.a,@.b,@.c)==1]", "invalid_selector": true }, { "name": "arg is a function expression", "selector": "$.values[?match(@.a, value($..['regex']))]", "document": { "regex": "a.*", "values": [ { "a": "ab" }, { "a": "ba" } ] }, "result": [ { "a": "ab" } ] } ] } length.json100644001750001750 433214612756433 25762 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/functions{ "tests": [ { "name": "string data", "selector" : "$[?length(@.a)>=2]", "document" : [{"a": "ab"}, {"a": "d"}], "result": [ {"a": "ab"} ] }, { "name": "string data, unicode", "selector": "$[?length(@)==2]", "document": ["☺", "☺☺", "☺☺☺", "ж", "жж", "жжж", "磨", "阿美", "形声字"], "result": ["☺☺", "жж", "阿美"] }, { "name": "array data", "selector" : "$[?length(@.a)>=2]", "document" : [{"a": [1,2,3]}, {"a": [1]}], "result": [ {"a": [1,2,3]} ] }, { "name": "missing data", "selector" : "$[?length(@.a)>=2]", "document" : [{"d": "f"}], "result": [] }, { "name": "number arg", "selector" : "$[?length(1)>=2]", "document" : [{"d": "f"}], "result": [] }, { "name": "true arg", "selector" : "$[?length(true)>=2]", "document" : [{"d": "f"}], "result": [] }, { "name": "false arg", "selector" : "$[?length(false)>=2]", "document" : [{"d": "f"}], "result": [] }, { "name": "null arg", "selector" : "$[?length(null)>=2]", "document" : [{"d": "f"}], "result": [] }, { "name": "result must be compared", "selector" : "$[?length(@.a)]", "invalid_selector": true }, { "name": "no params", "selector" : "$[?length()==1]", "invalid_selector": true }, { "name": "too many params", "selector" : "$[?length(@.a,@.b)==1]", "invalid_selector": true }, { "name": "non-singular query arg", "selector": "$[?length(@.*)<3]", "invalid_selector": true }, { "name": "arg is a function expression", "selector" : "$.values[?length(@.a)==length(value($..c))]", "document" : { "c": "cd", "values": [{"a": "ab"}, {"a": "d"}] }, "result": [ {"a": "ab"} ] }, { "name": "arg is special nothing", "selector" : "$[?length(value(@.a))>0]", "document" : [ {"a": "ab"}, {"c": "d"}, {"a": null} ], "result": [ {"a": "ab"} ] } ] } search.json100644001750001750 625314612756433 25752 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/functions{ "tests": [ { "name": "at the end", "selector" : "$[?search(@.a, 'a.*')]", "document" : [{"a": "the end is ab"}], "result": [ {"a": "the end is ab"} ] }, { "name": "double quotes", "selector" : "$[?search(@.a, \"a.*\")]", "document" : [{"a": "the end is ab"}], "result": [ {"a": "the end is ab"} ] }, { "name": "at the start", "selector" : "$[?search(@.a, 'a.*')]", "document" : [{"a": "ab is at the start"}], "result": [ {"a": "ab is at the start"} ] }, { "name": "in the middle", "selector" : "$[?search(@.a, 'a.*')]", "document" : [{"a": "contains two matches"}], "result": [ {"a": "contains two matches"} ] }, { "name": "regex from the document", "selector" : "$.values[?search(@, $.regex)]", "document" : {"regex": "b.?b", "values": ["abc", "bcd", "bab", "bba", "bbab", "b", true, [], {}]}, "result": ["bab", "bba", "bbab"] }, { "name": "don't select match", "selector" : "$[?!search(@.a, 'a.*')]", "document" : [{"a": "contains two matches"}], "result": [] }, { "name": "not a match", "selector" : "$[?search(@.a, 'a.*')]", "document" : [{"a": "bc"}], "result": [] }, { "name": "select non-match", "selector" : "$[?!search(@.a, 'a.*')]", "document" : [{"a": "bc"}], "result": [{"a": "bc"}] }, { "name": "non-string first arg", "selector" : "$[?search(1, 'a.*')]", "document" : [{"a": "bc"}], "result": [] }, { "name": "non-string second arg", "selector" : "$[?search(@.a, 1)]", "document" : [{"a": "bc"}], "result": [] }, { "name": "filter, search function, unicode char class, uppercase", "selector": "$[?search(@, '\\\\p{Lu}')]", "document": ["ж", "Ж", "1", "жЖ", true, [], {}], "result": ["Ж", "жЖ"] }, { "name": "filter, search function, unicode char class negated, uppercase", "selector": "$[?search(@, '\\\\P{Lu}')]", "document": ["ж", "Ж", "1", true, [], {}], "result": ["ж", "1"] }, { "name": "filter, search function, unicode, surrogate pair", "selector": "$[?search(@, 'a.b')]", "document": ["a\uD800\uDD01bc", "abc", "1", true, [], {}], "result": ["a\uD800\uDD01bc"] }, { "name": "result cannot be compared", "selector" : "$[?search(@.a, 'a.*')==true]", "invalid_selector": true }, { "name": "too few params", "selector" : "$[?search(@.a)]", "invalid_selector": true }, { "name": "too many params", "selector" : "$[?search(@.a,@.b,@.c)]", "invalid_selector": true }, { "name": "arg is a function expression", "selector" : "$.values[?search(@, value($..['regex']))]", "document" : { "regex": "b.?b", "values": [ "abc", "bcd", "bab", "bba", "bbab", "b", true, [], {} ] }, "result": ["bab", "bba", "bbab"] } ] } whitespace000755001750001750 014612756433 23570 5ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/testsslice.json100644001750001750 460014612756433 25722 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/whitespace{ "tests": [ { "name": "space between start and colon", "selector" : "$[1 :5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "newline between start and colon", "selector" : "$[1\n:5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "tab between start and colon", "selector" : "$[1\t:5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "return between start and colon", "selector" : "$[1\r:5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "space between colon and end", "selector" : "$[1: 5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "newline between colon and end", "selector" : "$[1:\n5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "tab between colon and end", "selector" : "$[1:\t5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "return between colon and end", "selector" : "$[1:\r5:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "space between end and colon", "selector" : "$[1:5 :2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "newline between end and colon", "selector" : "$[1:5\n:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "tab between end and colon", "selector" : "$[1:5\t:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "return between end and colon", "selector" : "$[1:5\r:2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "space between colon and step", "selector" : "$[1:5: 2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "newline between colon and step", "selector" : "$[1:5:\n2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "tab between colon and step", "selector" : "$[1:5:\t2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] }, { "name": "return between colon and step", "selector" : "$[1:5:\r2]", "document" : [1,2,3,4,5,6], "result": [ 2, 4 ] } ] } filter.json100644001750001750 717714612756433 26124 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/whitespace{ "tests": [ { "name": "space between question mark and expression", "selector" : "$[? @.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "newline between question mark and expression", "selector" : "$[?\n@.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "tab between question mark and expression", "selector" : "$[?\t@.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "return between question mark and expression", "selector" : "$[?\r@.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "space between question mark and parenthesized expression", "selector" : "$[? (@.a)]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "newline between question mark and parenthesized expression", "selector" : "$[?\n(@.a)]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "tab between question mark and parenthesized expression", "selector" : "$[?\t(@.a)]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "return between question mark and parenthesized expression", "selector" : "$[?\r(@.a)]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "space between parenthesized expression and bracket", "selector" : "$[?(@.a) ]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "newline between parenthesized expression and bracket", "selector" : "$[?(@.a)\n]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "tab between parenthesized expression and bracket", "selector" : "$[?(@.a)\t]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "return between parenthesized expression and bracket", "selector" : "$[?(@.a)\r]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "space between bracket and question mark", "selector" : "$[ ?@.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "newline between bracket and question mark", "selector" : "$[\n?@.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "tab between bracket and question mark", "selector" : "$[\t?@.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] }, { "name": "return between bracket and question mark", "selector" : "$[\r?@.a]", "document" : [{"a": "b", "d": "e"}, {"b": "c", "d": "f"}], "result": [ {"a": "b", "d": "e"} ] } ] }selectors.json100644001750001750 1246214612756433 26653 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/whitespace{ "tests": [ { "name": "space between root and bracket", "selector" : "$ ['a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "newline between root and bracket", "selector" : "$\n['a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "tab between root and bracket", "selector" : "$\t['a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "return between root and bracket", "selector" : "$\r['a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "space between bracket and bracket", "selector" : "$['a'] ['b']", "document" : {"a": {"b": "ab"} }, "result": [ "ab" ] }, { "name": "newline between root and bracket", "selector" : "$['a'] \n['b']", "document" : {"a": {"b": "ab"} }, "result": [ "ab" ] }, { "name": "tab between root and bracket", "selector" : "$['a'] \t['b']", "document" : {"a": {"b": "ab"} }, "result": [ "ab" ] }, { "name": "return between root and bracket", "selector" : "$['a'] \r['b']", "document" : {"a": {"b": "ab"} }, "result": [ "ab" ] }, { "name": "space between root and dot", "selector" : "$ .a", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "newline between root and dot", "selector" : "$\n.a", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "tab between root and dot", "selector" : "$\t.a", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "return between root and dot", "selector" : "$\r.a", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "space between dot and name", "selector" : "$. a", "invalid_selector": true }, { "name": "newline between dot and name", "selector" : "$.\na", "invalid_selector": true }, { "name": "tab between dot and name", "selector" : "$.\ta", "invalid_selector": true }, { "name": "return between dot and name", "selector" : "$.\ra", "invalid_selector": true }, { "name": "space between recursive descent and name", "selector" : "$.. a", "invalid_selector": true }, { "name": "newline between recursive descent and name", "selector" : "$..\na", "invalid_selector": true }, { "name": "tab between recursive descent and name", "selector" : "$..\ta", "invalid_selector": true }, { "name": "return between recursive descent and name", "selector" : "$..\ra", "invalid_selector": true }, { "name": "space between bracket and selector", "selector" : "$[ 'a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "newline between bracket and selector", "selector" : "$[\n'a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "tab between bracket and selector", "selector" : "$[\t'a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "return between bracket and selector", "selector" : "$[\r'a']", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "space between selector and bracket", "selector" : "$['a' ]", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "newline between selector and bracket", "selector" : "$['a'\n]", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "tab between selector and bracket", "selector" : "$['a'\t]", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "return between selector and bracket", "selector" : "$['a'\r]", "document" : {"a": "ab"}, "result": [ "ab" ] }, { "name": "space between selector and comma", "selector" : "$['a' ,'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] }, { "name": "newline between selector and comma", "selector" : "$['a'\n,'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] }, { "name": "tab between selector and comma", "selector" : "$['a'\t,'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] }, { "name": "return between selector and comma", "selector" : "$['a'\r,'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] }, { "name": "space between comma and selector", "selector" : "$['a', 'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] }, { "name": "newline between comma and selector", "selector" : "$['a',\n'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] }, { "name": "tab between comma and selector", "selector" : "$['a',\t'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] }, { "name": "return between comma and selector", "selector" : "$['a',\r'b']", "document" : {"a": "ab", "b": "bc"}, "result": [ "ab", "bc" ] } ] } functions.json100644001750001750 1213214612756433 26652 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/whitespace{ "tests": [ { "name": "space between function name and parenthesis", "selector" : "$[?count (@.*)==1]", "invalid_selector": true }, { "name": "newline between function name and parenthesis", "selector" : "$[?count\n(@.*)==1]", "invalid_selector": true }, { "name": "tab between function name and parenthesis", "selector" : "$[?count\t(@.*)==1]", "invalid_selector": true }, { "name": "return between function name and parenthesis", "selector" : "$[?count\r(@.*)==1]", "invalid_selector": true }, { "name": "space between parenthesis and arg", "selector" : "$[?count( @.*)==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "newline between parenthesis and arg", "selector" : "$[?count(\n@.*)==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "tab between parenthesis and arg", "selector" : "$[?count(\t@.*)==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "return between parenthesis and arg", "selector" : "$[?count(\r@.*)==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "space between arg and comma", "selector" : "$[?search(@ ,'[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "newline between arg and comma", "selector" : "$[?search(@\n,'[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "tab between arg and comma", "selector" : "$[?search(@\t,'[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "return between arg and comma", "selector" : "$[?search(@\r,'[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "space between comma and arg", "selector" : "$[?search(@, '[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "newline between comma and arg", "selector" : "$[?search(@,\n'[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "tab between comma and arg", "selector" : "$[?search(@,\t'[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "return between comma and arg", "selector" : "$[?search(@,\r'[a-z]+')]", "document" : [ "foo", "123" ], "result": [ "foo" ] }, { "name": "space between arg and parenthesis", "selector" : "$[?count(@.* )==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "newline between arg and parenthesis", "selector" : "$[?count(@.*\n)==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "tab between arg and parenthesis", "selector" : "$[?count(@.*\t)==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "return between arg and parenthesis", "selector" : "$[?count(@.*\r)==1]", "document" : [ {"a": 1}, {"b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "spaces in a relative singular selector", "selector" : "$[?length(@ .a .b) == 3]", "document" : [ {"a": {"b": "foo"}}, {} ], "result": [ {"a": {"b": "foo"}} ] }, { "name": "newlines in a relative singular selector", "selector" : "$[?length(@\n.a\n.b) == 3]", "document" : [ {"a": {"b": "foo"}}, {} ], "result": [ {"a": {"b": "foo"}} ] }, { "name": "tabs in a relative singular selector", "selector" : "$[?length(@\t.a\t.b) == 3]", "document" : [ {"a": {"b": "foo"}}, {} ], "result": [ {"a": {"b": "foo"}} ] }, { "name": "returns in a relative singular selector", "selector" : "$[?length(@\r.a\r.b) == 3]", "document" : [ {"a": {"b": "foo"}}, {} ], "result": [ {"a": {"b": "foo"}} ] }, { "name": "spaces in an absolute singular selector", "selector" : "$..[?length(@)==length($ [0] .a)]", "document" : [ {"a": "foo"}, {} ], "result": [ "foo" ] }, { "name": "newlines in an absolute singular selector", "selector" : "$..[?length(@)==length($\n[0]\n.a)]", "document" : [ {"a": "foo"}, {} ], "result": [ "foo" ] }, { "name": "tabs in an absolute singular selector", "selector" : "$..[?length(@)==length($\t[0]\t.a)]", "document" : [ {"a": "foo"}, {} ], "result": [ "foo" ] }, { "name": "returns in an absolute singular selector", "selector" : "$..[?length(@)==length($\r[0]\r.a)]", "document" : [ {"a": "foo"}, {} ], "result": [ "foo" ] } ] } operators.json100644001750001750 3337114612756433 26670 0ustar00tooktook000000000000JSON-Path-1.0.6/jsonpath-compliance-test-suite/tests/whitespace{ "tests": [ { "name": "space before ||", "selector" : "$[?@.a ||@.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "newline before ||", "selector" : "$[?@.a\n||@.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "tab before ||", "selector" : "$[?@.a\t||@.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "return before ||", "selector" : "$[?@.a\r||@.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "space after ||", "selector" : "$[?@.a|| @.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "newline after ||", "selector" : "$[?@.a||\n@.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "tab after ||", "selector" : "$[?@.a||\t@.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "return after ||", "selector" : "$[?@.a||\r@.b]", "document" : [ {"a": 1}, {"b": 2}, {"c": 3} ], "result": [ {"a": 1}, {"b": 2} ] }, { "name": "space before &&", "selector" : "$[?@.a &&@.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline before &&", "selector" : "$[?@.a\n&&@.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab before &&", "selector" : "$[?@.a\t&&@.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return before &&", "selector" : "$[?@.a\r&&@.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space after &&", "selector" : "$[?@.a&& @.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline after &&", "selector" : "$[?@.a&& @.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab after &&", "selector" : "$[?@.a&& @.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return after &&", "selector" : "$[?@.a&& @.b]", "document" : [ {"a": 1}, {"b": 2}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space before ==", "selector" : "$[?@.a ==@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "newline before ==", "selector" : "$[?@.a\n==@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "tab before ==", "selector" : "$[?@.a\t==@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "return before ==", "selector" : "$[?@.a\r==@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "space after ==", "selector" : "$[?@.a== @.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "newline after ==", "selector" : "$[?@.a==\n@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "tab after ==", "selector" : "$[?@.a==\t@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "return after ==", "selector" : "$[?@.a==\r@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 1} ] }, { "name": "space before !=", "selector" : "$[?@.a !=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline before !=", "selector" : "$[?@.a\n!=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab before !=", "selector" : "$[?@.a\t!=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return before !=", "selector" : "$[?@.a\r!=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space after !=", "selector" : "$[?@.a!= @.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline after !=", "selector" : "$[?@.a!=\n@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab after !=", "selector" : "$[?@.a!=\t@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return after !=", "selector" : "$[?@.a!=\r@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space before <", "selector" : "$[?@.a <@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline before <", "selector" : "$[?@.a\n<@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab before <", "selector" : "$[?@.a\t<@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return before <", "selector" : "$[?@.a\r<@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space after <", "selector" : "$[?@.a< @.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline after <", "selector" : "$[?@.a<\n@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab after <", "selector" : "$[?@.a<\t@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return after <", "selector" : "$[?@.a<\r@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space before >", "selector" : "$[?@.b >@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline before >", "selector" : "$[?@.b\n>@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab before >", "selector" : "$[?@.b\t>@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return before >", "selector" : "$[?@.b\r>@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space after >", "selector" : "$[?@.b> @.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "newline after >", "selector" : "$[?@.b>\n@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "tab after >", "selector" : "$[?@.b>\t@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "return after >", "selector" : "$[?@.b>\r@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ], "result": [ {"a": 1, "b": 2} ] }, { "name": "space before <=", "selector" : "$[?@.a <=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "newline before <=", "selector" : "$[?@.a\n<=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "tab before <=", "selector" : "$[?@.a\t<=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "return before <=", "selector" : "$[?@.a\r<=@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "space after <=", "selector" : "$[?@.a<= @.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "newline after <=", "selector" : "$[?@.a<=\n@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "tab after <=", "selector" : "$[?@.a<=\t@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "return after <=", "selector" : "$[?@.a<=\r@.b]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "space before >=", "selector" : "$[?@.b >=@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "newline before >=", "selector" : "$[?@.b\n>=@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "tab before >=", "selector" : "$[?@.b\t>=@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "return before >=", "selector" : "$[?@.b\r>=@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "space after >=", "selector" : "$[?@.b>= @.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "newline after >=", "selector" : "$[?@.b>=\n@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "tab after >=", "selector" : "$[?@.b>=\t@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "return after >=", "selector" : "$[?@.b>=\r@.a]", "document" : [ {"a": 1, "b": 1}, {"a": 1, "b": 2}, {"a": 2, "b": 1} ], "result": [ {"a": 1, "b": 1}, {"a": 1, "b": 2} ] }, { "name": "space between logical not and test expression", "selector": "$[?! @.a]", "document" : [{"a": "a", "d": "e"}, {"d": "f"}, {"a": "d", "d": "f"}], "result": [ {"d": "f"} ] }, { "name": "newline between logical not and test expression", "selector": "$[?!\n@.a]", "document" : [{"a": "a", "d": "e"}, {"d": "f"}, {"a": "d", "d": "f"}], "result": [ {"d": "f"} ] }, { "name": "tab between logical not and test expression", "selector": "$[?!\t@.a]", "document" : [{"a": "a", "d": "e"}, {"d": "f"}, {"a": "d", "d": "f"}], "result": [ {"d": "f"} ] }, { "name": "return between logical not and test expression", "selector": "$[?!\r@.a]", "document" : [{"a": "a", "d": "e"}, {"d": "f"}, {"a": "d", "d": "f"}], "result": [ {"d": "f"} ] }, { "name": "space between logical not and parenthesized expression", "selector": "$[?! (@.a=='b')]", "document" : [{"a": "a", "d": "e"}, {"a": "b", "d": "f"}, {"a": "d", "d": "f"}], "result": [ {"a": "a", "d": "e"}, {"a": "d", "d": "f"} ] }, { "name": "newline between logical not and parenthesized expression", "selector": "$[?!\n(@.a=='b')]", "document" : [{"a": "a", "d": "e"}, {"a": "b", "d": "f"}, {"a": "d", "d": "f"}], "result": [ {"a": "a", "d": "e"}, {"a": "d", "d": "f"} ] }, { "name": "tab between logical not and parenthesized expression", "selector": "$[?!\t(@.a=='b')]", "document" : [{"a": "a", "d": "e"}, {"a": "b", "d": "f"}, {"a": "d", "d": "f"}], "result": [ {"a": "a", "d": "e"}, {"a": "d", "d": "f"} ] }, { "name": "return between logical not and parenthesized expression", "selector": "$[?!\r(@.a=='b')]", "document" : [{"a": "a", "d": "e"}, {"a": "b", "d": "f"}, {"a": "d", "d": "f"}], "result": [ {"a": "a", "d": "e"}, {"a": "d", "d": "f"} ] } ] }