transerialize - transerialize files from a format to a different one


version 1.5.1


    # simple
    $ transerialize foo.yaml bar.json

    # with options
    $ transerialize pretty=1 foo.yaml bar.json

    # reading from STDIN
    $ cat foo.yaml | transerialize -.yaml bar.json

    # printing to STDOUT
    $ transerialize foo.yaml -.json


transerialize is a command-line interface to the File::Serialize function of the same name.

The command behaves pretty much like its underlying function, except for the details below.

Default options

All leading arguments containing an '=' will be considered default options. In other words,

    $ transerialize pretty=1 format=json foo bar

is equivalent to the script

    use File::Serialize { pretty => 1, format => 'json' };

    transerialize_file 'foo' => 'bar';

Code arguments

Any argument that begin with a '{', '[' or 'sub {' will be eval'ed (as opposed as being considered filenames).

Intermediary steps

Any intermediary step that doesn't look like code (as specified in the previous section) is doing to be interpreted as a Perl script returning a transformation function.

For example, you could grab the title of a blog entry and put it in the frontmatter via:

    $ transerialize ./ ./ -.json

with ./ looking like:

    sub {
        return $_ if $_->{title};

        $_->{title} = $1 if $_->{_content} =~ /^# (.*)/m;

        return $_;

Loading intermediary steps from file

Any of the argument passed to transerialize that has a leading @ is considered a serialized file containing a list of files and will be expanded. Useful if you do have a lot of intermediary steps and the command line is getting ungainly long.

For example, you could have

    # file ./process_blog.yml

    $ transerialize @./ -.json


An input filename which main part is a dash will be taken to be STDIN. For example

    $ transerialize_file -.yaml foo.json

will read STDIN, consider it to be YAML, and then convert it to JSON.

Likewise, an output file which main part is a dash will be printed on STDOUT. For example

    $ transerialize_file foo.yaml -.json

will print out the data of foo.yaml as JSON.

Accessing source and destination files

The original source and destination files are available to transformation scripts via the global variables $File::Serialize::SOURCE and $File::Serialize::DESTINATION.


Yanick Champoux <>


This software is copyright (c) 2021, 2019, 2017, 2016, 2015 by Yanick Champoux.

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