<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># 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 `==`, `!=`, `&lt;`, `&gt;`, `and`, `or`
- âś… Built-in functions: `length`, `keys`, `first`, `last`, `reverse`, `sort`, `unique`, `has`
- âś… Command-line interface: `jq-lite`
- âś… Reads from STDIN or file
- âś… **Interactive mode** for exploring JSON line-by-line

---

## đź¤” 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 &amp; 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-&gt;new;
my @names = $jq-&gt;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 &gt; 25)' users.json
jq-lite -r '.users[].name' users.json
```

&gt; âš&nbsp;ď¸Ź `jq-lite` is named to avoid conflict with the real `jq`.

---

### đź”„ Interactive Mode

If you omit the query, `jq-lite` enters **interactive mode**, allowing you to type queries line-by-line against a fixed JSON input.

```bash
jq-lite users.json
cat users.json | jq-lite
```

This launches:

```
jq-lite interactive mode. Enter query (empty line to quit):
&gt; .users[0].name
"Alice"
&gt; .users[] | select(.age &gt; 25)
{
  "name" : "Alice",
  "age" : 30,
  ...
}
```

- Results will be **re-rendered each time**, clearing the previous output (like a terminal UI).
- Works with `--raw-output` (`-r`) as well.

---

## đź“ 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 &gt; 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)
</pre></body></html>