JQ-Lite

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

  [Feature]
  - Add a jq-compatible @csv filter for formatting scalars and arrays as
    CSV output.

1.27  2025-10-24
  [Release]
  - Bump version to 1.27 to publish the select() predicate evaluation fixes.

1.26  2025-10-24
  [Behavior]
  - Run select() predicates as streaming filters so inputs pass once for each
    truthy predicate result while preserving compatibility with comparison
    expressions.

1.25  2025-10-23
  [CLI]
  - Fix YAML input handling in jq-lite: allow scalar (non-ref) results to be
    encoded without warnings or failure by adding `allow_nonref` to the
    JSON::PP encoder in `print_results`. This resolves failures in
    t/yaml_cli.t:
      * YAML files auto-detected by extension now work as expected.

Changes  view on Meta::CPAN

    - Documented conditional expressions across README, module POD, and the CLI
      help output.

1.09   2025-10-18
    - Promote the release version to 1.09 after adding jq-compatible
      foreach folding and test() helper support.

1.08   2025-10-18
    [Feature]
    - Added jq-compatible `foreach expr as $var (init; update [; extract])`
      folding with optional emitters so streaming reductions mirror jq.
    - Added jq-compatible `--slurp` (`-s`) option to wrap every JSON document
      from the input stream in a single array before executing filters.
    - Added jq's `test(pattern[, flags])` helper for regex matching with
      optional `imxs` modifiers.

    [Tests]
    - Added regression coverage ensuring foreach accumulates values and
      supports extract expressions referencing the iteration variable.
    - Added tests covering regex matches, flag handling, and array mapping via
      the new test() helper.

bin/jq-lite  view on Meta::CPAN

                   - Emit numbers from START (default 0) up to but not including END using STEP (default 1)
  enumerate()      - Pair each array element with its zero-based index
  transpose()      - Rotate arrays-of-arrays from rows into columns
  count            - Count total number of matching items
  map(EXPR)        - Map/filter array items with a subquery
  map_values(FILTER)
                   - Apply FILTER to each value in an object (dropping keys when FILTER yields no result)
  if COND then A [elif COND then B ...] [else Z] end
                  - jq-style conditional branching across optional elif/else chains
  foreach(EXPR as $var (init; update [; extract]))
                   - jq-compatible streaming reducer with lexical bindings and optional emitters
  walk(FILTER)     - Recursively apply FILTER to every value in arrays and objects
  recurse([FILTER])
                   - Emit the current value and depth-first descendants using optional FILTER for children
  add / sum        - Sum all numeric values in an array
  sum_by(KEY)      - Sum numeric values projected from each array item
  avg_by(KEY)      - Average numeric values projected from each array item
  median_by(KEY)   - Return the median of numeric values projected from each array item
  min_by(PATH)     - Return the element with the smallest projected value
  max_by(PATH)     - Return the element with the largest projected value
  product          - Multiply all numeric values in an array

lib/JQ/Lite/Filters.pm  view on Meta::CPAN

            return 1;
        }

        # support for select(...)
        if ($part =~ /^select\((.+)\)$/) {
            my $cond = $1;
            @next_results = ();

            my $has_wildcard_array = index($cond, '[]') != -1;
            my $has_comparison = ($cond =~ /(==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/i);
            my $use_streaming_eval = $has_wildcard_array || !$has_comparison;

            VALUE: for my $value (@results) {
                my $simple = JQ::Lite::Util::_evaluate_condition($value, $cond) ? 1 : 0;

                if ($use_streaming_eval) {
                    my $json = JQ::Lite::Util::_encode_json($value);
                    my $error;
                    my @cond_results;

                    {
                        local $@;
                        @cond_results = eval { $self->run_query($json, $cond) };
                        $error = $@;
                    }



( run in 0.225 second using v1.01-cache-2.11-cpan-5f4f29bf90f )