PHPackages                             moodev/weasel - 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. moodev/weasel

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

moodev/weasel
=============

Object marshalling library for PHP supporting JSON and XML

v0.17(11y ago)25199.0k12[12 issues](https://github.com/moodev/php-weasel/issues)[1 PRs](https://github.com/moodev/php-weasel/pulls)ISCPHPPHP &gt;=5.3.0

Since Jul 21Pushed 7y ago5 watchersCompare

[ Source](https://github.com/moodev/php-weasel)[ Packagist](https://packagist.org/packages/moodev/weasel)[ Docs](http://github.com/moodev/php-weasel)[ RSS](/packages/moodev-weasel/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (6)Versions (14)Used By (0)

PHP Weasel
==========

[](#php-weasel)

[![Build Status](https://camo.githubusercontent.com/84747b60bdc5c92bce342457652ee8cb1d97a6ca413f685f86111326abec8d07/68747470733a2f2f7472617669732d63692e6f72672f6d6f6f6465762f7068702d77656173656c2e706e67)](https://travis-ci.org/moodev/php-weasel)

Weasel is an object marshalling library for PHP supporting JSON and XML. Marshalling is, by default, configured using “annotations”, driven by the `Doctrine\Common\Annotation` library.

It also includes its own Annotation library, `Weasel\Annotation`, but this is considered deprecated in favour of using Doctrine.

The latest version can be found here:

The documentation can be found here:

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

[](#installation)

If you can, use [composer](http://getcomposer.org/). If you can't, you'll find the list of dependencies in [composer.json](./composer.json).

Usage
-----

[](#usage)

Annotate the classes you want to serialize/deserialize (see the documentation.)

Then:

```
$factory = new WeaselDoctrineAnnotationDrivenFactory();
// optionally:
    $factory->setCache($cacheInstance);
    $factory->setLogger($psr3LoggerInstance);

$mapper = $factory->getJsonMapperInstance();
$thing = $mapper->readString($json, $typeToDecodeTo);
$backToJson = $mapper->writeString($thing);
```

Why?
----

[](#why)

`json_decode()` decodes to arrays or stdObj. Weasel, while making use of `json_decode()` internally, maps to objects; it's basically a configuration driven Object Mapper for JSON.

Meanwhile, `json_encode()` gives you no fine grained control over how your data gets serialized to JSON. You can't disable marshalling of fields, you can't add typing information without adding it to your classes, and, most annoyingly, you don't have any control over how `array()` gets mapped on a field-by-field basis. Weasel allows you to configure how fields are marshalled on a per-field level: if you've got an array that should always be mapped as a JSON object, while other arrays need to be mapped as an array, you can have just that.

The `XmlMarshaller` just seemed like a good idea at the time. It probably wasn't. It's incomplete and unloved. As soon as I find a better approach to the problem, it'll be deprecated.

This project spawned from work on [moo-php](https://github.com/JonathanO/moo-php), a client library for the moo.com API. After writing serialization/deserialization code that was specific to that object structure, I realised that a general purpose, configurable marshaller, similar to Jackson in the Java world, would be rather useful. Weasel is the result.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.6% 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 ~90 days

Recently: every ~168 days

Total

12

Last Release

4094d ago

### Community

Maintainers

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

---

Top Contributors

[![JonathanO](https://avatars.githubusercontent.com/u/1206546?v=4)](https://github.com/JonathanO "JonathanO (202 commits)")[![icambridge](https://avatars.githubusercontent.com/u/196942?v=4)](https://github.com/icambridge "icambridge (1 commits)")[![kerrids](https://avatars.githubusercontent.com/u/1516735?v=4)](https://github.com/kerrids "kerrids (1 commits)")[![marcgear](https://avatars.githubusercontent.com/u/54014?v=4)](https://github.com/marcgear "marcgear (1 commits)")[![siad007](https://avatars.githubusercontent.com/u/2149445?v=4)](https://github.com/siad007 "siad007 (1 commits)")[![tsprlng](https://avatars.githubusercontent.com/u/547676?v=4)](https://github.com/tsprlng "tsprlng (1 commits)")

---

Tags

jsonserializationdeserializationmarshallmarshallingjackson

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/moodev-weasel/health.svg)

```
[![Health](https://phpackages.com/badges/moodev-weasel/health.svg)](https://phpackages.com/packages/moodev-weasel)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[jms/serializer

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

2.3k139.8M907](/packages/jms-serializer)

PHPackages © 2026

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