++ed by:
TOBYINK

1 PAUSE user

perlancar

NAME

dt - CLI data transformer

VERSION

This document describes version 0.002 of dt (from Perl distribution App-dt), released on 2017-05-19.

SYNOPSIS

 % dt [OPTIONS] [FILE]...

DESCRIPTION

Roughly similar to utilities like jq, jt, the App::PipeFilter suite, jsonsel, ddsel, yamlsel, this dt utility can be used to transform data structure on the CLI using Perl code. It accepts one or several files of encoded data structures in several formats (JSON, YAML, Perl), lets you specify Perl code to modify them, and spits them out again in specified format. The input data structures are put into $DATA[0], $DATA[1] and so on. The first data structure is also put in $DATA as well as $_.

Some examples:

  • Convert JSON to YAML

     % dt books.json -o books.yaml
  • Add a field to records, output to STDOUT

     % dt -e 'my $now = time; for (@$DATA) { $_->{status} = $_->{mtime} >= $now-7*86400 ? "new" : "" }' < books.json
  • Get YAML from STDIN, output it as Perl

     % other-cmd | dt -f yaml -F perl -o data

EXIT CODES

0 on success.

255 on I/O error.

99 on command-line options or input data error.

OPTIONS

  • -e CODE

    Specify Perl code to run. These variables are set: @DATA will be set to the data structures, in the order of the specified files, $DATA and $_ will also be set to the first data structure.

  • --overwrite

    Overwrite existing output files instead of skipping writing to output files when they already exist.

  • --default-input-format FORMAT, -f

    Set default output format. Default is json. Can also be yaml, perl.

  • --default-output-format FORMAT, -F

    Set default output format. Default is json. Can also be yaml, perl.

  • --output FILENAME, -o

    Add an output. Format will be guessed from .

    If not specified, will output all data to STDOUT.

ENVIRONMENT

DEBUG => bool

If set to true, print debugging messages.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-dt.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-dt.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-dt

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

jq

jt, App::PipeFilter, jsonsel, ddsel, yamlsel

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.