# JQ::Lite [![MetaCPAN](https://img.shields.io/cpan/v/JQ::Lite?color=blue)](https://metacpan.org/pod/JQ::Lite) [![GitHub](https://img.shields.io/github/stars/kawamurashingo/JQ-Lite?style=social)](https://github.com/kawamurashingo/JQ-Lite) **JQ::Lite** is a lightweight, pure-Perl JSON query engine inspired by the [`jq`](https://stedolan.github.io/jq/) command-line tool. It allows you to extract, traverse, and filter JSON data using a simplified jq-like syntax โ€” entirely within Perl. --- ## ๐Ÿ”ง Features - โœ… **Pure Perl** (no XS, no external binaries) - โœ… Dot notation (`.users[].name`) - โœ… Optional key access (`.nickname?`) - โœ… Array indexing and expansion (`.users[0]`, `.users[]`) - โœ… `select(...)` filters with `==`, `!=`, `<`, `>`, `and`, `or` - โœ… Built-in functions: `length`, `keys`, `first`, `last`, `reverse`, `sort`, `unique`, `has` - โœ… Command-line interface: `jq-lite` - โœ… Reads from STDIN or file --- ## ๐Ÿค” Why JQ::Lite (vs `jq` or `JSON::PP`)? | Use Case | Tool | |----------|------| | Simple JSON decode | โœ… `JSON::PP` | | Shell processing | โœ… `jq` | | jq-style queries in Perl | โœ… **JQ::Lite** | | Lightweight & portable | โœ… **JQ::Lite** | --- ## ๐Ÿ“ฆ Installation ```sh perl Makefile.PL make make test make install ``` --- ## ๐Ÿš€ Usage ### As a Perl module ```perl use JQ::Lite; my $json = '{"users":[{"name":"Alice"},{"name":"Bob"}]}'; my $jq = JQ::Lite->new; my @names = $jq->run_query($json, '.users[].name'); print join("\n", @names), "\n"; ``` ### As a command-line tool ```bash cat users.json | jq-lite '.users[].name' jq-lite '.users[] | select(.age > 25)' users.json jq-lite -r '.users[].name' users.json ``` > โš ๏ธ `jq-lite` is named to avoid conflict with the real `jq`. --- ## ๐Ÿ“˜ Example Input ```json { "users": [ { "name": "Alice", "age": 30, "profile": { "active": true, "country": "US" } }, { "name": "Bob", "age": 25, "profile": { "active": false, "country": "JP" } } ] } ``` ### Example Queries ```bash jq-lite '.users[].name' users.json jq-lite '.users | length' users.json jq-lite '.users[0] | keys' users.json jq-lite '.users[].nickname?' users.json jq-lite '.users[] | select(.age > 25)' users.json jq-lite '.users[] | select(.profile.active == true) | .name' users.json jq-lite '.users | sort | reverse | first' users.json ``` --- ## ๐Ÿงช Testing ```bash prove -l t/ ``` --- ## ๐Ÿ“ฆ CPAN ๐Ÿ‘‰ [JQ::Lite on MetaCPAN](https://metacpan.org/pod/JQ::Lite) --- ## ๐Ÿ“ License This module is released under the same terms as Perl itself. --- ## ๐Ÿ‘ค Author **Kawamura Shingo** ๐Ÿ“ง pannakoota1@gmail.com ๐Ÿ”— [GitHub @kawamurashingo](https://github.com/kawamurashingo/JQ-Lite)