JQ::Lite

JQ::Lite is a lightweight, pure-Perl JSON query engine inspired by the jq command-line tool.
It allows you to extract, traverse, and filter JSON data using a simplified jq-like query syntax โ€” entirely within Perl.

๐Ÿ”ง Features

๐Ÿค” Why JQ::Lite (vs jq or JSON::PP)?

While jq is a powerful CLI tool, JQ::Lite fills a different niche:

| Use Case | Tool | |----------|------| | Simple JSON parsing in Perl | โœ… JSON::PP | | Powerful CLI processing | โœ… jq | | Querying JSON inside Perl without shelling out | โœ… JQ::Lite | | Lightweight, portable scripting with no non-core deps | โœ… JQ::Lite | | jq-style syntax in Perl scripts (for filtering/traversal) | โœ… JQ::Lite |

JQ::Lite is particularly useful in environments where:

๐Ÿ›  Installation

perl Makefile.PL
make
make test
make install

After installation, the command-line tool will be available as jq-lite.

๐Ÿš€ Usage

As a Perl module

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 CLI tool

You can pipe JSON data from STDIN:

cat users.json | jq-lite '.users[] | .name'

Or provide the JSON file directly:

jq-lite '.users[] | .name' users.json

Or install it globally:

ln -s script/jq-lite ~/bin/jq-lite
chmod +x ~/bin/jq-lite

Then use it like this:

jq-lite '.users | length' users.json
jq-lite -r '.users[] | .name' users.json

โš ๏ธ Note: The executable is named jq-lite to avoid conflict with the official jq tool.

๐Ÿ“˜ Example Input

{
  "users": [
    {
      "name": "Alice",
      "age": 30,
      "profile": {
        "active": true,
        "country": "US"
      }
    },
    {
      "name": "Bob",
      "age": 25,
      "profile": {
        "active": false,
        "country": "JP"
      }
    }
  ]
}

Example Queries

jq-lite '.users[] | .name' users.json            # => "Alice", "Bob"
jq-lite '.users | length' users.json             # => 2
jq-lite '.users[0] | keys' users.json            # => ["age","name","profile"]
jq-lite '.users[].nickname?' users.json          # => No output, no error
jq-lite '.users[] | select(.age > 25)' users.json
jq-lite '.users[] | select(.profile.active == true) | .name' users.json

๐Ÿงช Testing

prove -l t/

๐Ÿ“ฆ CPAN

This module is available on CPAN:
๐Ÿ‘‰ JQ::Lite on MetaCPAN

๐Ÿ“ License

This module is released under the same terms as Perl itself.

๐Ÿ‘ค Author

Kawamura Shingo
๐Ÿ“ง pannakoota1@gmail.com
๐Ÿ”— GitHub: https://github.com/kawamurashingo/JQ-Lite