Git Product home page Git Product logo

json-converter's Introduction

JSON Converter

License GitHub issues GitHub stars GitHub forks

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:

composer require ramazancetinkaya/json-converter

Usage

// Include the Composer autoloader
require 'vendor/autoload.php';

use JSONConverter\JSONConverter;

Let's create a JSON data to use for this example:

$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:

// CSV file
$csvFilePath = 'employees.csv';

// XML file
$xmlFilePath = 'employees.xml';

Convert JSON to CSV:

// Convert JSON to CSV
JSONConverter::jsonToCSV($jsonData, 'output.csv');

Convert JSON to XML:

// Convert JSON to XML
JSONConverter::jsonToXML($jsonData, 'output.xml', true);

Convert CSV to JSON:

// Convert CSV to JSON
$jsonFromCSV = JSONConverter::csvToJSON($csvFilePath);
echo $jsonFromCSV;

Convert XML to JSON:

// 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 file.

Copyright

© 2024 Ramazan Çetinkaya. All rights reserved.

json-converter's People

Contributors

ramazancetinkaya avatar

Stargazers

Constantine Zavezeon avatar Ömer Arpacı avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.