Table of Contents

A propos

This howto will show you:

Steps

The tabular source data

In this howto, we will use as source books catalog data that are contained in

You can also used any other tabular data resources.

With the data print command, we can see the content.

tabul data print books.csv@howto
books.csv@howto
asin            description                                   price   group
-------------   -------------------------------------------   -----   ----------
B007US9NA8      The New Encyclopedia of Modern Bodybuilding   27.18   Sports
1439199191      How To Win Friends And Influence People       27.18   Psychology
9780465050659   The Design of Everyday Things                  9.99   Design
9780465050659   The Design of Everyday Things                  9.99   Psychology
B00555X8OA      Thinking, Fast and Slow                        8.85   Decision
B00555X8OA      Thinking, Fast and Slow                        8.85   Psychology

The JSON template

The JSON template is a template that represents the structure of the JSON resource that should be created that contains variables in the form Create Json From Tabular Data where name should match the column name of the source.

{
  "${group}": {
    "${asin}": {
      "price": "${price}",
      "description": "${description}"
    }
  }
}


where:

  • the variable ${group} matches the group column of the books.csv source
  • the variable ${asin} matches the asin column of the books.csv source
  • the variable ${price} matches the price column of the books.csv source
  • the variable ${description} matches the description column of the books.csv source

The template operation

Tabul Data Template Command

By running the below tabul data template operation, we will:

tabul data template --template-selectors books_template.json@howto books.csv@howto books.json@tmp
Transfer results
input                                  target           latency   record_count   error_code   error_message
------------------------------------   --------------   -------   ------------   ----------   -------------
favorite_books_books_template@memory   books.json@tmp   0.13s                1

The JSON file created

With the data print command, you can see the json file content created.

# type text because by default, a json file is seen as one JSON document, one record, one line
tabul data print --type text books.json@tmp
{
  "Sports": {
    "B007US9NA8": {
      "price": "27.18",
      "description": "The New Encyclopedia of Modern Bodybuilding"
    }
  },
  "Psychology": {
    "1439199191": {
      "price": "27.18",
      "description": "How To Win Friends And Influence People"
    },
    "9780465050659": {
      "price": "9.99",
      "description": "The Design of Everyday Things"
    },
    "B00555X8OA": {
      "price": "8.85",
      "description": "Thinking, Fast and Slow"
    }
  },
  "Design": {
    "9780465050659": {
      "price": "9.99",
      "description": "The Design of Everyday Things"
    }
  },
  "Decision": {
    "B00555X8OA": {
      "price": "8.85",
      "description": "Thinking, Fast and Slow"
    }
  }
}