Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ramazancetinkaya/json-converter
This library provides functionality to convert JSON data to various formats including CSV and XML, and vice versa
https://github.com/ramazancetinkaya/json-converter
csv-to-json json-converter json-to-csv json-to-xml xml-to-json
Last synced: 15 days ago
JSON representation
This library provides functionality to convert JSON data to various formats including CSV and XML, and vice versa
- Host: GitHub
- URL: https://github.com/ramazancetinkaya/json-converter
- Owner: ramazancetinkaya
- License: mit
- Created: 2024-05-11T18:26:05.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-14T19:46:29.000Z (9 months ago)
- Last Synced: 2024-05-15T15:09:26.613Z (9 months ago)
- Topics: csv-to-json, json-converter, json-to-csv, json-to-xml, xml-to-json
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Converter
[![License](https://img.shields.io/github/license/ramazancetinkaya/json-converter)](https://github.com/ramazancetinkaya/json-converter/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/ramazancetinkaya/json-converter)](https://github.com/ramazancetinkaya/json-converter/issues)
[![GitHub stars](https://img.shields.io/github/stars/ramazancetinkaya/json-converter)](https://github.com/ramazancetinkaya/json-converter/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/ramazancetinkaya/json-converter)](https://github.com/ramazancetinkaya/json-converter/network)JSON Converter is a PHP library that provides advanced functionality to convert data between JSON, CSV, and XML formats.
## Features
- Convert `JSON` data to `CSV` format.
- Convert `JSON` data to `XML` format.
- Convert `CSV` data to `JSON` format.
- Convert `XML` data to `JSON` format.
- Support for custom delimiters and enclosures in CSV files.
- Pretty print option for XML output.## Installation
You can install JSON Converter library via [Composer](https://getcomposer.org/):
```bash
composer require ramazancetinkaya/json-converter
```## Usage
```php
// Include the Composer autoloader
require 'vendor/autoload.php';use JSONConverter\JSONConverter;
```Let's create a JSON data to use for this example:
```php
$jsonData = '[
{
"id": 1,
"name": "John Doe",
"position": "Software Engineer",
"department": "Engineering",
"salary": 75000
},
{
"id": 2,
"name": "Jane Smith",
"position": "Marketing Manager",
"department": "Marketing",
"salary": 65000
},
{
"id": 3,
"name": "Michael Johnson",
"position": "HR Specialist",
"department": "Human Resources",
"salary": 55000
}
]';
```Files used for this example:
```php
// CSV file
$csvFilePath = 'employees.csv';// XML file
$xmlFilePath = 'employees.xml';
```Convert JSON to CSV:
```php
// Convert JSON to CSV
JSONConverter::jsonToCSV($jsonData, 'output.csv');
```Convert JSON to XML:
```php
// Convert JSON to XML
JSONConverter::jsonToXML($jsonData, 'output.xml', true);
```Convert CSV to JSON:
```php
// Convert CSV to JSON
$jsonFromCSV = JSONConverter::csvToJSON($csvFilePath);
echo $jsonFromCSV;
```Convert XML to JSON:
```php
// Convert XML to JSON
$jsonFromXML = JSONConverter::xmlToJSON($xmlFilePath);
echo $jsonFromXML;
```## Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.
## License
This project is licensed under the MIT License. For more details, see the [LICENSE](LICENSE) file.
## Copyright
© 2024 Ramazan Çetinkaya. All rights reserved.