PHPackages                             romtokarev/json-csv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. romtokarev/json-csv

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

romtokarev/json-csv
===================

JSON to CSV and CSV to JSON converters in PHP.

04PHP

Since Jul 28Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ROMTokarev/json-csv)[ Packagist](https://packagist.org/packages/romtokarev/json-csv)[ RSS](/packages/romtokarev-json-csv/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

JSON to CSV and CSV to JSON Converter Library in PHP
====================================================

[](#json-to-csv-and-csv-to-json-converter-library-in-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2a26cd57e0799e1d35ad94b4911e2fcf50492e796d25c5780148ee45ea58622e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f7a64656d6972627572616b2f6a736f6e2d6373762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ozdemirburak/json-csv)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/def5d514cf31413b754cd6a3c5f51597f9825189c1b59cdc576a415b86ff118f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6f7a64656d6972627572616b2f6a736f6e2d6373762f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ozdemirburak/json-csv)[![Total Downloads](https://camo.githubusercontent.com/60e99deb5558e3deba3ffa499b9f74d46d8c2aa8dd1368438f165ba7ece99a5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f7a64656d6972627572616b2f6a736f6e2d6373762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ozdemirburak/json-csv)

The most basic CSV to JSON and JSON to CSV converter library in PHP without any dependencies.

Install
-------

[](#install)

Via Composer

```
$ composer require romtokarev/json-csv
```

Usage
-----

[](#usage)

### JSON to CSV Converter from string

[](#json-to-csv-converter-from-string)

```
use OzdemirBurak\JsonCsv\File\Json;

// demo json data
$testJson = json_encode([
    [
        'name' => [
            'common' => 'Turkey',
            'official' => 'Republic of Turkey',
            'native' => 'T\u00fcrkiye'
        ],
        'area' => 783562,
        'latlng' => [39, 35]
    ],
    [
        'name' => [
            'common' => 'Israel',
            'official' => 'State of Israel',
            'native' => '\u05d9\u05e9\u05e8\u05d0\u05dc'
        ],
        'area' => 20770,
        'latlng' => [31.30, 34.45]

    ]
]);

// JSON to CSV
$json = (new Json())->convertfromString($testJson);
// To convert JSON to CSV string
$csvString = $json->convert();
// To set a conversion option then convert JSON to CSV and save
$json->setConversionKey('utf8_encoding', true);
$json->convertAndSave(__DIR__ . '/above.csv');
// To convert JSON to CSV and force download on browser
$json->convertAndDownload();
```

After the conversion, the resulting CSV data will look like below.

**name\_common****name\_official****name\_native****area****latlng\_0****latlng\_1**TurkeyRepublic of TurkeyTürkiye7835623935IsraelState of Israelישראל2077031.334.45### JSON to CSV Converter from file

[](#json-to-csv-converter-from-file)

```
use OzdemirBurak\JsonCsv\File\Json;

// JSON to CSV
$json = (new Json)->convertfromFile(__DIR__ . '/above.json');
// To convert JSON to CSV string
$csvString = $json->convert();
// To set a conversion option then convert JSON to CSV and save
$json->setConversionKey('utf8_encoding', true);
$json->convertAndSave(__DIR__ . '/above.csv');
// To convert JSON to CSV and force download on browser
$json->convertAndDownload();
```

Assume that the input JSON is something like below.

```
[
  {
    "name": {
      "common": "Turkey",
      "official": "Republic of Turkey",
      "native": "T\u00fcrkiye"
    },
    "area": 783562,
    "latlng": [39, 35]
  },
  {
    "name": {
      "common": "Israel",
      "official": "State of Israel",
      "native": "\u05d9\u05e9\u05e8\u05d0\u05dc"
    },
    "area": 20770,
    "latlng": [31.30, 34.45]
  }
]
```

After the conversion, the resulting CSV data will look like below.

**name\_common****name\_official****name\_native****area****latlng\_0****latlng\_1**TurkeyRepublic of TurkeyTürkiye7835623935IsraelState of Israelישראל2077031.334.45### CSV to JSON Converter

[](#csv-to-json-converter)

```
use OzdemirBurak\JsonCsv\File\Csv;

// CSV to JSON
$csv = new Csv(__DIR__ . '/below.csv');
$csv->setConversionKey('options', JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
// To convert CSV to JSON string
$jsonString = $csv->convert();
// To convert CSV to JSON and save
$csv->convertAndSave(__DIR__ . '/below.json');
// To convert CSV to JSON and force download on browser
$csv->convertAndDownload();
```

Assume that the input CSV file is something like below.

**SepalLength****SepalWidth****PetalLength****PetalWidth****Name**5.13.51.40.2Iris-setosa7.03.24.71.4Iris-versicolor6.33.36.02.5Iris-virginicaAfter the conversion, the resulting JSON data will look like below.

```
[
  {
    "SepalLength": "5.1",
    "SepalWidth": "3.5",
    "PetalLength": "1.4",
    "PetalWidth": "0.2",
    "Name": "Iris-setosa"
  },
  {
    "SepalLength": "7.0",
    "SepalWidth": "3.2",
    "PetalLength": "4.7",
    "PetalWidth": "1.4",
    "Name": "Iris-versicolor"
  },
  {
    "SepalLength": "6.3",
    "SepalWidth": "3.3",
    "PetalLength": "6.0",
    "PetalWidth": "2.5",
    "Name": "Iris-virginica"
  }
]
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Known Issues
------------

[](#known-issues)

Currently, there are not any issues that are known.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Burak Özdemir](https://github.com/ozdemirburak)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 53.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/97361c73db6314908c14a57094a9418e0eb2de6d1380097fd8f505c23ca0ec43?d=identicon)[ROMTokarev](/maintainers/ROMTokarev)

---

Top Contributors

[![ozdemirburak](https://avatars.githubusercontent.com/u/5355510?v=4)](https://github.com/ozdemirburak "ozdemirburak (15 commits)")[![ROMTokarev](https://avatars.githubusercontent.com/u/40247878?v=4)](https://github.com/ROMTokarev "ROMTokarev (4 commits)")[![intelliapps](https://avatars.githubusercontent.com/u/690875?v=4)](https://github.com/intelliapps "intelliapps (3 commits)")[![loekvangool](https://avatars.githubusercontent.com/u/7300472?v=4)](https://github.com/loekvangool "loekvangool (2 commits)")[![martinsustek](https://avatars.githubusercontent.com/u/3765387?v=4)](https://github.com/martinsustek "martinsustek (2 commits)")[![andreybolonin](https://avatars.githubusercontent.com/u/2576509?v=4)](https://github.com/andreybolonin "andreybolonin (1 commits)")[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (1 commits)")

### Embed Badge

![Health badge](/badges/romtokarev-json-csv/health.svg)

```
[![Health](https://phpackages.com/badges/romtokarev-json-csv/health.svg)](https://phpackages.com/packages/romtokarev-json-csv)
```

###  Alternatives

[ozdemir/datatables

Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly.

273158.4k](/packages/ozdemir-datatables)[that0n3guy/transliteration

Transliteration provides one-way string transliteration (romanization) and cleans text by replacing unwanted characters.

1296.5k4](/packages/that0n3guy-transliteration)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
