No commit activity in last 3 years
No release in over 3 years
This gem provides a converter between an existing JSON file and an existing CSV file. The Mapping is provided via YAML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

JSON CSV Converter

This gem is built to help at the migration between existing JSON files into the mappings of existing CSV tables and vice versa. To map the keys you provide a YAML file.

Status

Build Status Dependency Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'json_csv_converter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install json_csv_converter

Usage

To convert the data of an existing JSON file into an existing CSV table just run JSONCSVConverter::json_to_csv with the JSON path, the CSV path and the YAML mapping file path as arguments. This method returns a CSV::Table.

The gem also provides an executable named json_csv_converter. It currently only supports conversion from JSON to CSV. If you run

$ json_csv_converter <i>path_to_json</i> <i>path_to_csv</i> <i>path_to_yaml_mapping</i>

you get the completely converted CSV table as String for further processing.

Example:

# create an instance to work with
converter = JSONCSVConverter::Converter.new(json_path,csv_path,mapping_path)

# map each JSON Object to a CSV row
converter.json_to_csv

# get the CSV table
csv_table = converter.csv_table

# get the JSON instance
json = converter.json

# Or simply run the toplevel method
csv_table = JSONCSVConverter.json_to_csv(json_path,csv_path,mapping_path)