Bulk Import from JSON file

This article explains how to import data from JSON files to Treasure Data.

Table of Contents

Install Bulk Loader

First, install the toolbelt, which includes bulk loader program, on your computer.


After the installation, the td command will be installed on your computer. Open up the terminal, and type td to execute the command. Also, please make sure you have java as well. Execute td import:jar_update to download the up-to-date version of our bulk loader:

$ td
usage: td [options] COMMAND [args]
$ java
Usage: java [-options] class [args...]
$ td import:jar_update
Installed td-import.jar 0.x.xx into /path/to/.td/java


Please login to your Treasure Data account.

$ td account -f
Enter your Treasure Data credentials.
Email: xxxxx
Password (typing will be hidden): 
Authenticated successfully.
Use 'td db:create <db_name>' to create a database.

Importing data from a JSON

Suppose you have a file called data.json and its content looks like this:

$ head -n 1 data.json
{"host":"","user":"-","method":"GET","path":"/category/electronics","code":200,"referer":"-","size":43,"agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)","date_time":"2004-03-07 16:05:49"}

Execute the following command to upload the JSON file:

$ td db:create my_db
$ td table:create my_db my_tbl
$ td import:auto \
  --format json \
  --time-column date_time \
  --time-format "%Y-%m-%d %H:%M:%S" \
  --auto-create my_db.my_tbl \
Because `td import:auto` executes MapReduce jobs to check the invalid rows, it'll take at least 1-2 minutes.
If the column chosen for `--time-column` is in epoch timestamp (or unix time), you don't need the `--time-format` flag.

In the above command, we assumed that:

  • The data file is called data.json and is located in the current directory (hence ./data.json)
  • The JSON format typically specifies the column names. If it does not, you will have to specify the column names with the --columns options (and optionally the column types with --column-types option), or use the --column-types for each column in the file.
  • The time field is called “date_time” and it’s specified with the --time-column option
  • The time format is %Y-%m-%d %H:%M:%S and it’s specified with the --time-format option

For further details, check the following pages:

Last modified: Feb 24 2017 09:27:52 UTC

If this article is incorrect or outdated, or omits critical information, please let us know. For all other issues, please see our support channels.