PHPackages                             tan-sandbox/json-rest - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tan-sandbox/json-rest

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tan-sandbox/json-rest
=====================

Json response builder.

0.8.2(8y ago)015BSD-3-ClausePHPPHP &gt;=5.3.0

Since Jul 24Pushed 8y agoCompare

[ Source](https://github.com/tansandbox/json-rest)[ Packagist](https://packagist.org/packages/tan-sandbox/json-rest)[ RSS](/packages/tan-sandbox-json-rest/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)DependenciesVersions (3)Used By (0)

json-rest
=========

[](#json-rest)

Json response builder library for php.

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

[](#installation)

### Composer

[](#composer)

Add to your composer.json or create a new composer.json:

```
{
    "require": {
        "tansandbox/json-rest": "*"
    }
}
```

Tell the composer to download the library by running the command:

```
$ php composer.phar install
```

To include using compser require, run the following command from your project.

```
$ php composer.phar require tansandbox/json-rest
```

Basic usages
------------

[](#basic-usages)

### Creating object

[](#creating-object)

```
use TanSandbox\JsonRest\Builder;
$builder = new Builder() ;
```

### Returning a success response

[](#returning-a-success-response)

```
$data = array (
    'name' => 'Nithin',
    'subject' => 'English',
    'mark' => '90'
);
$builder->ok()->send($data) ;
```

Will produce

```
{
    "status": true,
    "data": {
        "name": "Nithin",
        "subject": "English",
        "mark": "90"
    }
}
```

### Return a failure

[](#return-a-failure)

```
$data = array(
    'name' => 'Please provide a valid name'
);
$builder->fail()->send($data) ;
```

Will produce

```
{
    "status": false,
    "data": {
        "name": "Please provide a valid name"
    }
}
```

### Response with custom http status

[](#response-with-custom-http-status)

```
$data = array(
    'reply' => 'Resource not found.'
);
$builder->setStatus(404)->send($data) ;
```

Will produce

```
{
    "status": false,
    "data": {
        "reply": "Resource not found."
    }
}
```

### Advanced response

[](#advanced-response)

```
$data = array (
    'name' => 'Nithin',
    'subject' => 'English',
    'mark' => '90'
);
$builder->setMessage('Action completed')->setStatus(200)->send($data) ;
```

Will produce

```
{
    "status": false,
    "data": {
        "name": "Nithin",
        "subject": "English",
        "mark": "90"
    },
    "message": "Action completed"
}
```

### Method chaining.

[](#method-chaining)

New json member can be added using the setXXX methods. The sendie() method is to output the reponse and to die after that.

```
$builder->setName('Nithin')
    ->setSubject('English')
    ->setMark('90')
    ->setCustomNotes('Student of ZF2')
    ->sendie() ;
```

Will produce

```
{
    "status": true,
    "message": "Action completed",
    "name": "Nithin",
    "subject": "English",
    "mark": "90",
    "customNotes": "Student of ZF2"
}
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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 ~4 days

Total

2

Last Release

3261d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/30142556?v=4)[tansandbox](/maintainers/tansandbox)[@tansandbox](https://github.com/tansandbox)

---

Top Contributors

[![tansandbox](https://avatars.githubusercontent.com/u/30142556?v=4)](https://github.com/tansandbox "tansandbox (13 commits)")

### Embed Badge

![Health badge](/badges/tan-sandbox-json-rest/health.svg)

```
[![Health](https://phpackages.com/badges/tan-sandbox-json-rest/health.svg)](https://phpackages.com/packages/tan-sandbox-json-rest)
```

PHPackages © 2026

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