PHPackages                             shkm/jsend - 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. shkm/jsend

Abandoned → [NanneHuiges/JSend](/?search=NanneHuiges%2FJSend)Library[Parsing &amp; Serialization](/categories/parsing)

shkm/jsend
==========

A simple PHP implementation of the JSend specification.

v5.0.0(5y ago)3142.8k5BSD-3-ClausePHPPHP &gt;=7.4CI passing

Since Apr 11Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/shkm/JSend)[ Packagist](https://packagist.org/packages/shkm/jsend)[ Docs](https://github.com/NanneHuiges/jsend)[ RSS](/packages/shkm-jsend/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)Dependencies (1)Versions (11)Used By (0)

[![Build Status](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpunit_php81.yml/badge.svg)](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpunit_php81.yml/badge.svg)[![Build Status](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpunit_php82.yml/badge.svg)](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpunit_php82.yml/badge.svg)[![Build Status](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpunit_php83.yml/badge.svg)](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpunit_php83.yml/badge.svg)[![Build Status](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpmd.yml/badge.svg)](https://github.com/NanneHuiges/JSend/actions/workflows/ci_phpmd.yml/badge.svg)

[![Code Climate](https://camo.githubusercontent.com/8a0477cd254fc23abd34b5247ab623bd56fdc0f1e6703b4c7363cf42a1234a47/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4e616e6e654875696765732f4a53656e642f6261646765732f6770612e737667)](https://codeclimate.com/github/NanneHuiges/JSend)
[![Issue Count](https://camo.githubusercontent.com/25a323f4a7ff9d3f95c00951b3726a05ea99d669eb04b6e296f7d43a87df3846/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4e616e6e654875696765732f4a53656e642f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/NanneHuiges/JSend)

[![Total Downloads](https://camo.githubusercontent.com/1ffc04db4feaf79b70d642c901e657181f3e491ef7bcaf85f312f2ee4d28da39/68747470733a2f2f706f7365722e707567782e6f72672f6e616e6e656875696765732f6a73656e642f646f776e6c6f616473)](https://packagist.org/packages/nannehuiges/jsend)

JSend
=====

[](#jsend)

A simple PHP implementation of the [JSend specification](https://github.com/omniti-labs/jsend).

Usage
-----

[](#usage)

```
use JSend\JSendResponse;
```

### New response

[](#new-response)

```
$success = new JSendResponse('success', $data);
$fail = new JSendResponse('fail', $data);
$error = new JSendResponse('error', $data, 'Not cool.', 9001);
```

```
$success = JSendResponse::success($data);
$fail = JSendResponse::fail($data);
$error = JSendResponse::error('Not cool.', 9001, $data);
```

**Note**: an `InvalidJSendException` is thrown if the status is invalid or if you're creating an `error` without a `message`.

### Convert JSendResponse to JSON

[](#convert-jsendresponse-to-json)

`__toString()` is overridden to encode JSON automatically.

```
$json = $success->encode();
$json = (string) $success;
```

As JSendResponse is `JsonSerializable`, you can use the object directly in `json_encode`

```
json_encode($success);
```

#### Setting flags

[](#setting-flags)

You can set flags if needed:

```
$success->setEncodingOptions(\JSON_PRETTY_PRINT | \JSON_BIGINT_AS_STRING);
$json = $success->encode();
```

### Convert JSON to JSendResponse

[](#convert-json-to-jsendresponse)

```
try {
    $response = JSendResponse::decode($json);
} catch (InvalidJSendException $e) {
    echo "You done gone passed me invalid JSend.";
}
```

### Send JSON as HTTP Response

[](#send-json-as-http-response)

This sets the `Content-Type` header to `application/json` and spits out the JSON.

```
$jsend = new JSendResponse('success', $data);
$jsend->respond();
```

### Get info

[](#get-info)

```
$isSuccess = $response->isSuccess();
$isError = $response->isError();
$isFail = $response->isFail();
$status = $response->getStatus();
$data = $response->getData();
$array = $response->asArray();
```

Additionally, you can call the following methods on an error. A `BadMethodCallException` is thrown if the status is not `error`, so check first.

```
if ($response->isError()) {
    $code = $response->getErrorCode;
    $message = $response->getErrorMessage;
}
```

Development
===========

[](#development)

For your convenience, there is a dockerfile with the right dependencies (php, composer) available. Please use those to run various things (composer, phpunit, etc). You will need `docker` installed, but you don't need `PHP` or `composer` or any of the other dependencies.

Setting up and using a local environment
----------------------------------------

[](#setting-up-and-using-a-local-environment)

To start using the local environment for testing and debugging all you have to is open a shell in the root folder of where this project is checked out. Then run the following command.

```
make build install
```

This command should be run occasionally to keep the local environment up to date. For instance when the composer dependencies are changed.

### Using the shell

[](#using-the-shell)

To open a shell in the docker container run the following command.

```
make shell
```

Available commands are in `/bin`

### Running the code quality tools locally

[](#running-the-code-quality-tools-locally)

We use a variety of tools to keep the code quality of the library high. To run one the tools you only need to run

```
make
```

Available tools:

- `phpstan` [PHPStan](https://phpstan.org/) is static analyser tool that can detect various code issues.
- `phpunit` [PHPUnit](https://phpunit.de/) is the unit testing framework we use for this library.
- `codeclimate` [CodeClimate](https://codeclimate.com/github/NanneHuiges/JSend)

Notes
-----

[](#notes)

- Note that the `composer.lock` file is ignored.

Credits
=======

[](#credits)

The library was written by [Jamie Schembri](https://github.com/shkm). It has been transfered to the current account [Nanne Huiges](https://github.com/NanneHuiges) in december 2015.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance56

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 84% 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 ~323 days

Recently: every ~483 days

Total

10

Last Release

1868d ago

Major Versions

v1.2.1 → v2.0.02015-12-15

v2.1.0 → v3.0.02018-07-11

v3.0.0 → v4.0.02019-12-09

v4.0.0 → v5.0.02021-04-02

PHP version history (5 changes)v1.0.0PHP &gt;=5.3.0

v2.0.0PHP &gt;=5.4.0

v3.0.0PHP &gt;=7.0

v4.0.0PHP &gt;=7.2

v5.0.0PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![NanneHuiges](https://avatars.githubusercontent.com/u/1526794?v=4)](https://github.com/NanneHuiges "NanneHuiges (89 commits)")[![shkm](https://avatars.githubusercontent.com/u/22677?v=4)](https://github.com/shkm "shkm (11 commits)")[![jeremykendall](https://avatars.githubusercontent.com/u/288613?v=4)](https://github.com/jeremykendall "jeremykendall (3 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![jorritidsardi](https://avatars.githubusercontent.com/u/217586559?v=4)](https://github.com/jorritidsardi "jorritidsardi (1 commits)")[![Kalipso0505](https://avatars.githubusercontent.com/u/3777168?v=4)](https://github.com/Kalipso0505 "Kalipso0505 (1 commits)")

---

Tags

phpjsonjsend

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shkm-jsend/health.svg)

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

###  Alternatives

[nannehuiges/jsend

A simple PHP implementation of the JSend specification.

31368.1k2](/packages/nannehuiges-jsend)[adhocore/json-fixer

Fix/repair truncated JSON data

51543.2k2](/packages/adhocore-json-fixer)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[josantonius/json

PHP simple library for managing Json files.

1621.6k10](/packages/josantonius-json)

PHPackages © 2026

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