https://github.com/alexoid1/csv_json_converter
This gem converts a csv string to json object and vice versa.
https://github.com/alexoid1/csv_json_converter
Last synced: over 1 year ago
JSON representation
This gem converts a csv string to json object and vice versa.
- Host: GitHub
- URL: https://github.com/alexoid1/csv_json_converter
- Owner: Alexoid1
- License: mit
- Created: 2023-08-23T01:34:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-05T22:45:39.000Z (almost 3 years ago)
- Last Synced: 2025-02-24T05:03:50.390Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# CsvJsonConverter
[](https://rubygems.org/gems/csv_json_converter)
- [:green_book: Table of Contents](#-table-of-contents)
- [:book: csv\_json\_converter ](#-csv_json_converter-)
- [Installation ](#installation-)
- [Usage](#usage)
- [Convert csv to json](#csv-to-json)
- [Convert json to csv](#json-to-csv)
- [:busts_in_silhouette: Authors ](#-authors-)
- [:handshake: Contributing ](#-contributing-)
- [:star:️ Show your support ](#️-show-your-support-)
# :book: csv_json_convert
This gem converts a csv string to json object.
## Installation
Add the following code to you Gemfile
```
gem 'csv_json_converter'
```
or
install the gem on your terminal
```
gem install csv_json_converter
```
### Usage
`require` this gem on the top of your ruby code.
### Csv to json
If you want to convert `csv string`, to json you can use `to_json` method from `CsvJsonConverter`. Let's see how:-
For example
```ruby
require 'csv_json_converter'
data_csv='file;text;number;hex
test18.csv;CMkABfAGXvmSFV;9892576;jz40cbafbec8d6f92e93d22ea6ef5b'
json_data = CsvJsonCoverter.to_json(data_csv)
print json_data
```
**The output looks like below**
```
{ "file": "test18.csv",
"text": "CMkABfAGXvmSFV",
"number": 9892576,
"hex": "jz40cbafbec8d6f92e93d22ea6ef5b"
}
```
### Json to csv
If you want to convert `json object`, to json you can use `to_csv` method from `CsvJsonConverter`. Let's see how:-
For example
```ruby
require 'csv_json_converter'
data_json={ "file": "test18.csv",
"text": "CMkABfAGXvmSFV",
"number": 9892576,
"hex": "jz40cbafbec8d6f92e93d22ea6ef5b"
}
csv_data = CsvJsonCoverter.to_csv(data_json)
print csv_data
```
**The output looks like below**
```
"file,text,number,hex\ntest18.csv,CMkABfAGXvmSFV,9892576,jz40cbafbec8d6f92e93d22ea6ef5b"
```
## :busts_in_silhouette: Authors
:bust_in_silhouette: Pablo Zambrano
- GitHub: [@alexoid1](https://github.com/melashu)
- Twitter: [@pablo_acz](https://twitter.com/meshu102)
- LinkedIn: [Pablo Alexis Zambrano](https://www.linkedin.com/in/alexzambranocoral/)
## :handshake: Contributing
This repo is open for contributions. Issues, and feature requests are welcome!
Feel free to check the [issues page.](https://github.com/melashu/csv_json_converter/issues)
## :star:️ Show your support
Give a star if you like this project!