PHPackages                             abgeo/xml-to-json - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. abgeo/xml-to-json

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

abgeo/xml-to-json
=================

Simple way to convert XML to JSON

v1.0.0(6y ago)54.6k↓16.7%[1 issues](https://github.com/ABGEO/xml-to-json/issues)[1 PRs](https://github.com/ABGEO/xml-to-json/pulls)1MITPHPPHP ^7.2

Since May 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ABGEO/xml-to-json)[ Packagist](https://packagist.org/packages/abgeo/xml-to-json)[ Docs](https://github.com/ABGEO/xml-to-json)[ RSS](/packages/abgeo-xml-to-json/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (1)

xml-to-json
===========

[](#xml-to-json)

Simple way to convert XML to JSON.

[![Build Status](https://camo.githubusercontent.com/dbc53596e1b293f5def574c4048aa0496957309a8e8e02236a8baee10c87361f/68747470733a2f2f7472617669732d63692e636f6d2f414247454f2f786d6c2d746f2d6a736f6e2e7376673f6272616e63683d312e78)](https://travis-ci.com/ABGEO/xml-to-json?branch=1.x)[![Coverage Status](https://camo.githubusercontent.com/db1e532edd3ee92c7987cb8dad6e70c617ee1f37cbef6ef036feecc521736c39/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f414247454f2f786d6c2d746f2d6a736f6e2f62616467652e7376673f6272616e63683d312e78)](https://coveralls.io/github/ABGEO/xml-to-json?branch=1.x)[![GitHub release](https://camo.githubusercontent.com/631838e129eb95a36ce01bef6734b21ab75d7e581147096820fc8a9fa95d2c57/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f414247454f2f786d6c2d746f2d6a736f6e2e737667)](https://github.com/ABGEO/xml-to-json/releases)[![Packagist Version](https://camo.githubusercontent.com/4d4d3acf13504125a649c2c61baab968602ad06562622ead5e43655e283ce75e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616267656f2f786d6c2d746f2d6a736f6e2e737667)](https://packagist.org/packages/abgeo/xml-to-json)[![GitHub license](https://camo.githubusercontent.com/8c17e10eaeca82c1cccb6c1e1c47e3b4aa8745495a5405217f5afe059cf4f998/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f414247454f2f786d6c2d746f2d6a736f6e2e737667)](https://github.com/ABGEO/xml-to-json/blob/master/LICENSE)

Installation
------------

[](#installation)

You can install this library with [Composer](https://getcomposer.org/):

- `composer require abgeo/xml-to-json`

Usage
-----

[](#usage)

Include composer autoloader in your main file (Ex.: index.php)

- `require __DIR__.'/../vendor/autoload.php';`

This package gives you the ability to convert XML string/file to JSON string/file.
For this, we have two converters:

- `ABGEO\XmlToJson\StringConverter`
- `ABGEO\XmlToJson\FileConverter`

Let's look at them in action.

### Convert XML String to JSON string

[](#convert-xml-string-to-json-string)

Create simple XML file:

`example.xml`

```

    Temuri
    Takalandze
    true

        Developer

            IT

```

Create an object of class `ABGEO\XmlToJson\StringConverter` and read the content of `example.xml` into a variable:

```
$converter = new StringConverter();
$xmlContent = file_get_contents(__DIR__ . '/example.xml');
```

Now you can convert value of `$xmlContent` variable to JSON object:

```
$jsonContent = $converter->convert($xmlContent);
```

if you print this variable, you will get the following result:

```
echo $jsonContent;

//{
//    "profile": {
//    "firstName": "Temuri",
//        "lastName": "Takalandze",
//        "active": "true",
//        "position": {
//        "title": "Developer",
//            "department": {
//            "title": "IT"
//            }
//        }
//    }
//}
```

### Convert XML file to JSON file

[](#convert-xml-file-to-json-file)

Consider that you already have the `example.xml` file described in the step above. Now let's create an object of `ABGEO\XmlToJson\FileConverter` class:

```
$converter = new FileConverter();
```

Using the `convert` method of this object, you can simply convert the XML file to a JSON file:

```
$converter->convert(__DIR__ . '/example.xml', __DIR__ . '/example.json');
```

`Convert()` takes two arguments - the path to the input and output files. If you do not specify an output file, by default it will be {$inputFile}.json.

Finally, the `Convert ()` method will generate a new `example.json` with the following content:

`example.json`

```
{
    "profile": {
        "firstName": "Temuri",
        "lastName": "Takalandze",
        "active": "true",
        "position": {
            "title": "Developer",
            "department": {
                "title": "IT"
            }
        }
    }
}
```

**See full example [here](examples).**

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Authors
-------

[](#authors)

- [**Temuri Takalandze**](https://abgeo.dev) - *Initial work*

License
-------

[](#license)

Copyright © 2020 [Temuri Takalandze](https://abgeo.dev).
Released under the [MIT](LICENSE) license.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% 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 ~26 days

Total

2

Last Release

2172d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/003cac08dd47c34ad3a5ed454c2968ed6afea9e26d57033867d4166fa08b3555?d=identicon)[ABGEO](/maintainers/ABGEO)

---

Top Contributors

[![ABGEO](https://avatars.githubusercontent.com/u/19558543?v=4)](https://github.com/ABGEO "ABGEO (12 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

converterjsonxmlxml-to-jsonjsonxmlconverterXMLtoJSON

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/abgeo-xml-to-json/health.svg)

```
[![Health](https://phpackages.com/badges/abgeo-xml-to-json/health.svg)](https://phpackages.com/packages/abgeo-xml-to-json)
```

###  Alternatives

[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[goetas-webservices/xsd2php

Convert XSD (XML Schema) definitions into PHP classes and JMS metadata

2411.6M37](/packages/goetas-webservices-xsd2php)[goetas-webservices/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

4910.9M36](/packages/goetas-webservices-xsd2php-runtime)[akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

40443.2k1](/packages/akrabat-rka-content-type-renderer)

PHPackages © 2026

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