PHPackages                             mjohnson/type-converter - 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. mjohnson/type-converter

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

mjohnson/type-converter
=======================

Converts one resource to another (XML, JSON, Object, Array, Serialization).

2.0.0(13y ago)3452.1k83MITPHPPHP &gt;=5.2

Since Jul 8Pushed 11y ago6 watchersCompare

[ Source](https://github.com/milesj/type-converter)[ Packagist](https://packagist.org/packages/mjohnson/type-converter)[ Docs](http://milesj.me/code/php/type-converter)[ RSS](/packages/mjohnson-type-converter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (3)

Type Converter v2.0.0
=====================

[](#type-converter-v200)

A class that handles the detection and conversion of certain resource formats / content types into other formats. The current formats are supported: XML, JSON, Array, Object, Serialized

Requirements
------------

[](#requirements)

- PHP 5.3+ - v2.x
- PHP 5.2+ - v1.x
- SimpleXML -

Documentation
-------------

[](#documentation)

The class is pretty straight forward. If you want to convert something to another format, use the "to" methods.

```
$object = TypeConverter::toObject($resource);
$array = TypeConverter::toArray($resource);
$json = TypeConverter::toJson($resource);
$xml = TypeConverter::toXml($resource);
$ser = TypeConverter::toSerialize($resource);

```

If you want to detect what resource type it is, use the "is" methods. If you use the "to" methods above, it does automatic "is" detection.

```
TypeConverter::isObject($resource);
TypeConverter::isArray($resource);
TypeConverter::isJson($resource);
TypeConverter::isXml($resource);
TypeConverter::isSerialized($resource);

```

If you want a string representation of what a resource is, use the default is() method.

```
$resource = array();
TypeConverter::is($resource); // array

```

Finally, you can convert an XML document into an array (must have SimpleXML).

```
$array = TypeConverter::xmlToArray($xml, TypeConverter::XML_MERGE);

```

When using xmlToArray(), you can define the format in which the node attributes and values are presented. The following constants are available.

```
XML_NONE  - Disregard XML attributes and only return the value.
XML_MERGE - Merge attributes and the value into a single dimension; the values key will be "value".
XML_GROUP - Group the attributes into a key of "attributes" and the value into a key of "value".
XML_OVERWRITE - Attributes will only be returned.

```

Be sure to set the content type when supporting UTF-8.

```

```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~67 days

Total

3

Last Release

4918d ago

Major Versions

1.4.1 → 2.0.02012-11-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/7fde949ba5bf8f6af95b77cf88fe1362c4cc7519edbcd4f8891f1564da621fdb?d=identicon)[milesj](/maintainers/milesj)

---

Top Contributors

[![milesj](https://avatars.githubusercontent.com/u/143744?v=4)](https://github.com/milesj "milesj (23 commits)")

---

Tags

typeconverter

### Embed Badge

![Health badge](/badges/mjohnson-type-converter/health.svg)

```
[![Health](https://phpackages.com/badges/mjohnson-type-converter/health.svg)](https://phpackages.com/packages/mjohnson-type-converter)
```

###  Alternatives

[goetas-webservices/xsd2php

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

2411.6M36](/packages/goetas-webservices-xsd2php)[pixel418/markdownify

The HTML to Markdown converter for PHP

196800.8k8](/packages/pixel418-markdownify)[goetas-webservices/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

4910.9M34](/packages/goetas-webservices-xsd2php-runtime)[kartik-v/yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0

88265.8k6](/packages/kartik-v-yii2-markdown)[wpreadme2markdown/wpreadme2markdown

Convert WordPress Plugin readme.txt to Markdown

9564.6k4](/packages/wpreadme2markdown-wpreadme2markdown)[3f/converter

A set of classes to translate a text from HTML to BBcode and from BBCode to Markdown.

29148.7k](/packages/3f-converter)

PHPackages © 2026

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