Skip to content

Alexoid1/csv_json_converter

Repository files navigation

CsvJsonConverter

csv_json_ - converter

📖 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

    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

    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"

👥 Authors

👤 Pablo Zambrano

🤝 Contributing

This repo is open for contributions. Issues, and feature requests are welcome! Feel free to check the issues page.

⭐️ Show your support

Give a star if you like this project!

(back to top)

About

This gem converts a csv string to json object and vice versa.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published