PHPackages                             ozdemirburak/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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ozdemirburak/json-csv

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ozdemirburak/json-csv
=====================

JSON to CSV and CSV to JSON converters in PHP.

1.0.0(5mo ago)40166.5k↓16.1%171MITPHPPHP ^8.1CI passing

Since Feb 26Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/ozdemirburak/json-csv)[ Packagist](https://packagist.org/packages/ozdemirburak/json-csv)[ Docs](https://github.com/ozdemirburak/json-csv)[ RSS](/packages/ozdemirburak-json-csv/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (1)

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/a1e7efca505851cef44481ae01d0e4c1b930d386dd4ad79ef95ed2e5bbdd199c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f7a64656d6972627572616b2f6a736f6e2d6373762f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/ozdemirburak/json-csv/actions/workflows/tests.yml)[![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 ozdemirburak/json-csv
```

Note: Requires PHP 8.1 or higher with JSON extension

Usage
-----

[](#usage)

### JSON to CSV Converter

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

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

// JSON to CSV
$json = new Json(__DIR__ . '/file.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__ . '/file.csv');
// To convert JSON to CSV and force download on browser
$json->convertAndDownload();
```

You can also convert directly from a JSON string using the `fromString` method.

```
$csvString = (new Json())->fromString('{"name": "John", "age": 30}')->convert();
```

Assume that the input JSON is something like below.

```
[
  {
    "name": {
      "common": "Türkiye",
      "official": "Republic of Türkiye",
      "native": "Türkiye"
    },
    "area": 783562,
    "latlng": [39, 35]
  },
  {
    "name": {
      "common": "Japan",
      "official": "Japan",
      "native": "日本"
    },
    "area": 377975,
    "latlng": [36, 138]
  }
]
```

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

name\_commonname\_officialname\_nativearealatlng\_0latlng\_1TürkiyeRepublic of TürkiyeTürkiye7835623935JapanJapan日本37797536138#### JSON Conversion Options

[](#json-conversion-options)

OptionTypeDefaultDescription`delimiter`string`,`CSV field delimiter`enclosure`string`"`CSV field enclosure character`escape`string`\`CSV escape character`join`string`_`Character used to join nested keys`null`mixed`null`Value to use for null/missing fields`utf8_encoding`bool`false`Add UTF-8 BOM to output### CSV to JSON Converter

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

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

// CSV to JSON
$csv = new Csv(__DIR__ . '/file.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__ . '/file.json');
// To convert CSV to JSON and force download on browser
$csv->convertAndDownload();
```

You can also convert directly from a CSV string using the `fromString` method.

```
$jsonString = (new Csv())->fromString("name,age\nJohn,30\n")->convert();
```

Assume that the input CSV file is something like below.

SepalLengthSepalWidthPetalLengthPetalWidthName5.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"
  }
]
```

#### CSV Conversion Options

[](#csv-conversion-options)

OptionTypeDefaultDescription`delimiter`string`,`CSV field delimiter`enclosure`string`"`CSV field enclosure character`escape`string`\`CSV escape character`join`string`_`Character used to split nested keys`numeric`bool`false`Set to `true` to convert numeric strings to numbers`options`int`0`JSON encode flags (e.g., `JSON_PRETTY_PRINT`)Change log
----------

[](#change-log)

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

Testing
-------

[](#testing)

```
composer test
```

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

58

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 58.8% 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.

###  Release Activity

Cadence

Every ~473 days

Recently: every ~652 days

Total

7

Last Release

162d ago

Major Versions

0.4.0 → 1.0.02025-12-08

PHP version history (5 changes)0.0.1PHP ~7.0

0.2.0PHP ~7.1

0.3.0PHP ~7.2

0.4.0PHP ^7.3|^8.0

1.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ae2e490cb81102d1561dbb71328aeb1b2ea77ea93ebc409cd9e285228b65ea9?d=identicon)[ozdemirburak](/maintainers/ozdemirburak)

---

Top Contributors

[![ozdemirburak](https://avatars.githubusercontent.com/u/5355510?v=4)](https://github.com/ozdemirburak "ozdemirburak (20 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)")[![theadeyemiolayinka](https://avatars.githubusercontent.com/u/64863320?v=4)](https://github.com/theadeyemiolayinka "theadeyemiolayinka (2 commits)")[![Julian-Forrer](https://avatars.githubusercontent.com/u/187400488?v=4)](https://github.com/Julian-Forrer "Julian-Forrer (2 commits)")[![moebrowne](https://avatars.githubusercontent.com/u/8448512?v=4)](https://github.com/moebrowne "moebrowne (1 commits)")[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (1 commits)")[![andreybolonin](https://avatars.githubusercontent.com/u/2576509?v=4)](https://github.com/andreybolonin "andreybolonin (1 commits)")

---

Tags

csv-convertercsv2jsoncsvtojsonjson-converterjson2csvjsontocsvjsoncsvjson2csvjson to csvcsv to jsoncsv2json

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[mledoze/countries

List of world countries in JSON, CSV, XML and YAML

6.2k699.7k6](/packages/mledoze-countries)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

582599.4k1](/packages/faisalman-simple-excel-php)[kartik-v/yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)

1623.1M35](/packages/kartik-v-yii2-export)[rodenastyle/stream-parser

PHP Multiformat Streaming Parser

443195.7k2](/packages/rodenastyle-stream-parser)[ee/dataexporter-bundle

Easy export data to CSV, XML, HTML, JSON or XLS

4982.5k](/packages/ee-dataexporter-bundle)[dracoblue/craur

A lossless xml to json and json to xml converter (and csv/xlsx/yaml). Writing PHP Json/Xml/Csv/Yaml/excel Importers made easy

4643.1k2](/packages/dracoblue-craur)

PHPackages © 2026

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