PHPackages                             middlewares/payload - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. middlewares/payload

ActiveLibrary[HTTP &amp; Networking](/categories/http)

middlewares/payload
===================

Middleware to parse the body of the request with support for json, csv and url-encode

v3.1.0(1y ago)32466.8k—2.3%516MITPHPPHP ^7.2 || ^8.0CI passing

Since Oct 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/middlewares/payload)[ Packagist](https://packagist.org/packages/middlewares/payload)[ Docs](https://github.com/middlewares/payload)[ RSS](/packages/middlewares-payload/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (15)Used By (16)

middlewares/payload
===================

[](#middlewarespayload)

[![Latest Version on Packagist](https://camo.githubusercontent.com/25adc14008d859a644cd712d7200f04225e5c29d88c733404428a467e90411c8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6964646c6577617265732f7061796c6f61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/payload)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Testing](https://github.com/middlewares/payload/workflows/testing/badge.svg)](https://github.com/middlewares/payload/workflows/testing/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/a1267be49d8dadb20027bae1128308f6369ba1668a3c9405cc521bfcaa0c77ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6964646c6577617265732f7061796c6f61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/payload)

Parses the body of the request if it's not parsed and the method is POST, PUT or DELETE. It contains the following components to support different formats:

- [JsonPayload](#jsonpayload)
- [UrlEncodePayload](#urlencodepayload)
- [CsvPayload](#csvpayload)
- [XmlPayload](#xmlpayload)

Failure to parse the body will result in a `Middlewares\Utils\HttpErrorException` being thrown. See [middlewares/utils](https://github.com/middlewares/utils#httperrorexception) for additional details.

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

[](#requirements)

- PHP &gt;= 7.2
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

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

[](#installation)

This package is installable and autoloadable via Composer as [middlewares/payload](https://packagist.org/packages/middlewares/payload).

```
composer require middlewares/payload
```

JsonPayload
-----------

[](#jsonpayload)

Parses the JSON payload of the request.

```
Dispatcher::run([
    (new Middlewares\JsonPayload())
        ->associative(false)
        ->depth(64)
]);

$response = $dispatcher->dispatch(new ServerRequest());
```

Contains the following options to configure the [json\_decode](http://php.net/manual/en/function.json-decode.php) function:

### associative

[](#associative)

Enabled by default, convert the objects into associative arrays.

```
//Disable associative arrays
$payload = (new Middlewares\JsonPayload())->associative(false);
```

### depth

[](#depth)

To configure the recursion depth option of json\_decode. By default is `512`.

### options

[](#options)

To pass the bitmask of json\_decode options: `JSON_BIGINT_AS_STRING` (enabled by default), `JSON_OBJECT_AS_ARRAY`, `JSON_THROW_ON_ERROR`.

### methods

[](#methods)

To configure the allowed methods. By default only the requests with the method `POST, PUT, PATCH, DELETE, COPY, LOCK, UNLOCK` are handled.

```
//Parse json only with POST and PUT requests
$payload = (new Middlewares\JsonPayload())->methods(['POST', 'PUT']);
```

### contentType

[](#contenttype)

To configure all `Content-Type` headers allowed in the request. By default is `application/json`

```
//Parse json only in request with these two Content-Type values
$payload = (new Middlewares\JsonPayload())->contentType(['application/json', 'text/json']);
```

### override

[](#override)

To override the previous parsed body if exists (`false` by default)

UrlEncodePayload
----------------

[](#urlencodepayload)

Parses the url-encoded payload of the request.

```
Dispatcher::run([
    new Middlewares\UrlEncodePayload()
]);
```

### methods

[](#methods-1)

To configure the allowed methods. By default only the requests with the method `POST, PUT, PATCH, DELETE, COPY, LOCK, UNLOCK` are handled.

### contentType

[](#contenttype-1)

To configure all Content-Type headers allowed in the request. By default is `application/x-www-form-urlencoded`

### override

[](#override-1)

To override the previous parsed body if exists (`false` by default)

CsvPayload
----------

[](#csvpayload)

CSV payloads are supported by the [middlewares/csv-payload](https://packagist.org/packages/middlewares/csv-payload) package.

XmlPayload
----------

[](#xmlpayload)

Parses the XML payload of the request. Parsed body will return an instance of [SimpleXMLElement](https://www.php.net/manual/en/class.simplexmlelement.php).

### methods

[](#methods-2)

To configure the allowed methods. By default only the requests with the method `POST, PUT, PATCH, DELETE, COPY, LOCK, UNLOCK` are handled.

### contentType

[](#contenttype-2)

To configure all Content-Type headers allowed in the request. By default is `text/xml`, `application/xml` and `application/x-xml`.

### override

[](#override-2)

To override the previous parsed body if exists (`false` by default)

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance46

Moderate activity, may be stable

Popularity45

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 80.8% 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 ~237 days

Recently: every ~581 days

Total

14

Last Release

422d ago

Major Versions

v0.6.0 → v1.0.02018-01-25

v1.0.0 → v2.0.02018-06-25

v2.1.1 → v3.0.02019-11-29

PHP version history (4 changes)v0.1.0PHP ^5.6 || ^7.0

v0.6.0PHP ^7.0

v3.0.0PHP ^7.2

v3.0.1PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e99df56b617f4af8cf0556a51a0ca20c7420104920c57d7e9eab093f92bb744f?d=identicon)[oscarotero](/maintainers/oscarotero)

![](https://www.gravatar.com/avatar/42e0d72f42eb7d84f67e20d28606da42e5a3248ca908b1eadb4366aafeae2561?d=identicon)[filisko](/maintainers/filisko)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (59 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (8 commits)")[![nyamsprod](https://avatars.githubusercontent.com/u/51073?v=4)](https://github.com/nyamsprod "nyamsprod (3 commits)")[![andreybolonin](https://avatars.githubusercontent.com/u/2576509?v=4)](https://github.com/andreybolonin "andreybolonin (1 commits)")[![cseufert](https://avatars.githubusercontent.com/u/1734519?v=4)](https://github.com/cseufert "cseufert (1 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (1 commits)")

---

Tags

httpjsonpayloadpsr-15urlencodehttppsr-7jsonmiddlewareserverpsr-15payloadurl-encode

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/middlewares-payload/health.svg)

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

###  Alternatives

[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[middlewares/fast-route

Middleware to use FastRoute

96191.1k15](/packages/middlewares-fast-route)[middlewares/negotiation

Middleware to implement content negotiation

47442.1k11](/packages/middlewares-negotiation)[middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

35302.0k2](/packages/middlewares-http-authentication)[middlewares/whoops

Middleware to use Whoops as error handler

33205.4k24](/packages/middlewares-whoops)[middlewares/firewall

Middleware to provide IP filtering

12318.3k2](/packages/middlewares-firewall)

PHPackages © 2026

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