jt - JSON Transformer


version 0.43


jt works only with data from input pipe. Here are some examples. For quick references on command line options, run jt -h. For more comprehensive documentation, run perldoc =jt.

    # prettyfied
    curl | jt

    # uglified
    cat random.json | jt --ugly > random.min.json

    # take only selected fields
    cat cities.json | jt --field name,country,latlon

    ## --pick, --grep, -map assumes the input is an array.
    # randomly pick 10 hashes
    cat cities.json | jt --pick 10

    # pick 10 hashes from position 100, and uglified the output
    cat cities.json | jt --pick 100..109 --ugly

    # filtered by code
    cat cities.json | jt --grep '$_{country} eq "us"' | jt --field name,latlon

    # convert to csv. Only scalar values are chosen.
    cat cities.json | jt --csv

    # Run a piece of code on each hash
    cat orders.json | jt --map 'say "$_{name} sub-total: " . $_{count} * $_{price}'


jt assumes the input is some data serialized as JSON, and perform transformation based on its parameter. It can be used to deal with various RESTful web service api, such as ElasticSearch.


The default output format is JSON. If --csv is provided then simple fields are chosen and then converted to CSV. If --tsv is provided then it becomes tab-separated values.


The --field option can be used to select only the wanted fields in the output.

The field name notation is based on Hash::Flatten or MongoDB. "." is used to delimit sub-fields within a hash, and ":" is used to delimit array elements. Here's a brief example table that maps such flatten notation with perl expression:

    | flatten notation | perl expression        |
    |                  |                        |
    |          | $_->{foo}{bar}         |
    | foo:0            | $_->{foo}[0]           |
    |    | $_->{foo}{bar}[3]{baz} |
    |      | $_->{foo}{0}{bar}{4}   |

The --fields option transform the input such that the output contain only values of those fields. It may contain multilpe values seperated by comma, such as:

    --fields title,address,phone

Each specified field name is matched to the flatten notation of full field names. So "title" would match any "title" field an any depth in the input.

Then the input is an array of hash, then it applies on the hashes inside, so the selection can be simplified.


JSONPath is a more comprehensive way to specify the elements within a JSON structure. See the full description of JSONPath at

To specify a JSONPath selector, use --json-path option. Here are some simple examples:

    cat store.json | jt --json-path '$'   # Get all book authors
    cat store.json | jt --json-path '$[:2]' # The first 2 books.

    # print unique authors
    cat store.json | bin/jt --json-path '$' | bin/jt --silent --map 'say $_' | sort -u


Kang-min Liu <>


This software is Copyright (c) 2013 by Kang-min Liu.

This is free software, licensed under:

  The MIT (X11) License