2017 © Pedro Peláez
 

library csv-json-converter

Convert CSV to JSON and JSON to CSV file format using PHP

image

pearl/csv-json-converter

Convert CSV to JSON and JSON to CSV file format using PHP

  • Tuesday, March 13, 2018
  • by pearlkrishn
  • Repository
  • 0 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 100 % Grown

The README.md

Build Status, (*1)

Convert CSV to JSON and JSON to CSV using PHP.

Installation

composer require pearl/csv-json-converter, (*2)

## How to use?, (*3)

### JSON to CSV: ##### Sample Json Data: php $jsonString = '[{ "name": "Half Girlfriend", "author": "Chetan Bhagat", "publisher": "Rupa Publications", "language": "en" }, { "name": "My Journey: Transforming Dreams into Actions", "author": "A.P.J. Abdul Kalam", "publisher": "Rupa Publications", "language": "en" }]';, (*4)

use Pearl\CsvJsonConverter\Type\JsonToCsv;  
Data loading:
  • Array or Json values are accepted.
  • Custom output header optional available. This is optional parameter if not passed then default header will be considered.
$jsonToCsv = new JsonToCsv($jsonString, ['headers' => ["productName", "author", "publisher", "lang"]]);

Or load the json data from file., (*5)

$jsonToCsv->load(__Dir__ . '/data/products.json');
Data conversion result options :

$jsonToCsv->convertAndSave(__Dir__ . '/output');


$jsonToCsv->convertAndDownload(__Dir__ . '/output');


$jsonToCsv->convert();

Output:

name author publisher language
Half Girlfriend Chetan Bhagat Rupa Publications en
My Journey: Transforming Dreams into Actions A.P.J. Abdul Kalam Rupa Publications en

CSV to JSON:

use Pearl\CsvJsonConverter\Type\CsvToJson;

Load the CSV data., (*6)

$csvToJson = new CsvToJson($csvString, ['bitmask' => 'JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES']);

Or Load the csv data from file., (*7)

$csvToJson->load(__Dir__ . '/data/products.csv');
Data conversion result options :

$csvToJson->convertAndSave(__Dir__ . '/output');


$csvToJson->convertAndDownload(__Dir__ . '/output');


$csvToJson->convert();

Sample Csv:

name author publisher language
Half Girlfriend Chetan Bhagat Rupa Publications en
My Journey: Transforming Dreams into Actions A.P.J. Abdul Kalam Rupa Publications en

Output:

  [{
        "name": "Half Girlfriend",
        "author": "Chetan Bhagat",
        "publisher": "Rupa Publications",
        "language": "en"
    },
    {
        "name": "My Journey: Transforming Dreams into Actions",
        "author": "A.P.J. Abdul Kalam",
        "publisher": "Rupa Publications",
        "language": "en"
    }
  ]

The Versions

13/03 2018

dev-master

9999999-dev

Convert CSV to JSON and JSON to CSV file format using PHP

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

by Avatar pearlkrishn

csv php json json to csv csv to json data converter

13/03 2018

1.0

1.0.0.0

Convert CSV to JSON and JSON to CSV file format using PHP

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

by Avatar pearlkrishn

csv php json json to csv csv to json data converter