Converting JSON into CSV Using Pig

In this blog we will see how to convert JSON format of data into CSV format.
We have created our own JSON format data from a CSV file using AVRO file format and we will be using the same JSON data in this blog.

You can also download the dataset from this link.

We will now load the JSON data into pig using the below command

Pig provides API for loading Json format of data, Using the above command we can load the data into pig.

In this case, we are using JsonLoader() as our loader function .

Now we have successfully loaded the JSON data into pig, to convert it into CSV we just need to store the JSON data with CSV API provided by pig.

 

If we load JSON data using JSON loader, the data will be parsed automatically by the loader and will be visible as CSV format. You can see the output in the below screenshot.

The above command will store the output using CSV storage available with pig.

You can download the CSV file from the location /pig_conversions/json_to_csv with name part-m-00000.

The output looks like this

By using this CSV format, performing analysis on the data becomes easier.

Hope this blog helped you in learning how to convert JSON format of data into CSV format using pig.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s