Tabulify HowTo - How to create JSON file(s) from Tabular data with a JSON template

Tabulify HowTo - How to create JSON file(s) from Tabular data with a JSON template

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.

tabli data print [email protected]
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 ${name} 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

Tabli Data Template Command

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

tabli data template --template-selector [email protected] [email protected] [email protected]
Source         Target            Latency (ms)   Row Count   Error   Message   
------------   ---------------   ------------   ---------   -----   -------   
[email protected]   [email protected]   6              0

The JSON file created

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

tabli data print [email protected]
{
  "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"
    }
  }
}
Powered by ComboStrap