JQ-Lite

 view release on metacpan or  search on metacpan

bin/jq-lite  view on Meta::CPAN

        if ($@) {
            my $err = $@ || 'Unknown error';
            $err =~ s/\s+\z//;
            _runtime_error($err);
        }
        push @results, @line_results;
    }
}
else {
    @results = eval { $jq->run_query($json_text, $query) };
    if ($@) {
        my $err = $@ || 'Unknown error';
        $err =~ s/\s+\z//;
        _runtime_error($err);
    }
}

my $status = 0;
if ($exit_status) {
    my $last = @results ? $results[-1] : undef;
    $status = _is_truthy($last) ? 0 : 1;
}

sub print_supported_functions {
    print <<'EOF';

Supported Functions:
  length           - Count array elements, hash keys, or characters in scalars
  keys             - Extract sorted keys from a hash or indexes from an array
  keys_unsorted    - Extract object keys without sorting (jq-compatible)
  values           - Extract values from a hash (v0.34)
  leaf_paths()     - Emit only terminal paths to leaf values
  sort             - Sort array items
  sort_desc        - Sort array items in descending order
  sort_by(KEY)     - Sort array of objects by key
  pluck(KEY)       - Collect a key's value from each object in an array
  pick(KEYS...)    - Build new objects containing only the supplied keys (arrays handled element-wise)
  merge_objects()  - Merge arrays of objects into a single hash (last-write-wins)
  unique           - Remove duplicate values
  unique_by(KEY)   - Remove duplicates by projecting each item on KEY
  reverse          - Reverse an array
  first / last     - Get first / last element of an array
  limit(N)         - Limit array to first N elements
  drop(N)          - Skip the first N elements of an array
  rest             - Drop the first element of an array
  tail(N)          - Return the final N elements of an array
  chunks(N)        - Split array into subarrays each containing up to N items
  range(START; END[, STEP])
                   - 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
  scalars          - Pass through only scalar inputs (string/number/bool/null)
  objects          - Pass through only object inputs
  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
  min / max        - Return minimum / maximum numeric value in an array
  avg              - Return the average of numeric values in an array
  median           - Return the median of numeric values in an array
  mode             - Return the most frequent value in an array (ties pick earliest occurrence)
  percentile(P)    - Return the requested percentile (0-100 or 0-1) of numeric array values
  variance         - Return the variance of numeric values in an array
  stddev           - Return the standard deviation of numeric values in an array
  abs              - Convert numbers (and array elements) to their absolute value
  ceil()           - Round numbers up to the nearest integer
  floor()          - Round numbers down to the nearest integer
  round()          - Round numbers to the nearest integer (half-up semantics)
  clamp(MIN, MAX)  - Clamp numeric values within an inclusive range
  tostring()       - Convert values into their JSON string representation
  @json            - Format the input as JSON text (jq-style formatter)
  @csv             - Format arrays/scalars as a single CSV row
  @tsv             - Format arrays/scalars as a single TSV row
  @base64          - Encode input as a Base64 string
  @base64d         - Decode Base64-encoded text into strings/arrays
  @uri             - Percent-encode text (URL-safe)
  tojson()         - Encode values as JSON text regardless of type
  fromjson()       - Decode JSON text into native values (arrays handled element-wise)
  tonumber() / to_number()
                   - Coerce numeric-looking strings/booleans into numbers
  nth(N)           - Get the Nth element of an array (zero-based index)
  index(VALUE)     - Return the zero-based index of VALUE within arrays or strings
  rindex(VALUE)    - Return the zero-based index of the last VALUE within arrays or strings
  indices(VALUE)   - Return every index where VALUE occurs within arrays or strings
  group_by(KEY)    - Group array items by field
  group_count(KEY) - Count grouped items by field
  join(SEPARATOR)  - Join array elements with a string
  split(SEPARATOR) - Split string values (and arrays of strings) by a literal separator
  substr(START[, LENGTH])
                   - Extract substring using zero-based indices (arrays handled element-wise)
  slice(START[, LENGTH])
                  - Return a subarray using zero-based indices (negative starts count from the end)
  replace(OLD; NEW)
                   - Replace literal substrings (arrays handled element-wise)
  to_entries       - Convert objects/arrays into [{"key","value"}, ...] pairs
  from_entries     - Convert entry arrays back into an object
  with_entries(FILTER)
                   - Transform entries using FILTER and rebuild an object
  delpaths(PATHS)  - Delete keys at the supplied PATHS array (jq-compatible)
  has              - Check if objects contain a key or arrays expose an index
  contains         - Check if strings include a fragment, arrays contain an element, or hashes have a key
  contains_subset(VALUE)
                   - jq-style subset containment for arrays (order-insensitive)
  inside(CONTAINER) - Check if the input value is contained within CONTAINER
  any([FILTER])    - Return true if any input (optionally filtered) is truthy
  all([FILTER])    - Return true if every input (optionally filtered) is truthy
  not              - Logical negation following jq truthiness rules



( run in 0.376 second using v1.01-cache-2.11-cpan-140bd7fdf52 )