PHPackages                             smhnaqvi/json-response - 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. [API Development](/categories/api)
4. /
5. smhnaqvi/json-response

ActiveLibrary[API Development](/categories/api)

smhnaqvi/json-response
======================

simple library for rest apis to create easily json response

1.0(2y ago)341MITPHPPHP &gt;=7.4

Since Mar 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/smhnaqvi/php-json-response)[ Packagist](https://packagist.org/packages/smhnaqvi/json-response)[ RSS](/packages/smhnaqvi-json-response/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

php-json-response
=================

[](#php-json-response)

#### simple library for rest apis to create easily json response

[](#simple-library-for-rest-apis-to-create-easily-json-response)

```
// create response instance
$res = new Response();
```

### ::setStatus

[](#setstatus)

set your response status accept boolean value `true or false`

```
$res->setStatus(false); // default value is false
```

### ::setData

[](#setdata)

you can set data using this method accept any format data such as `string,object,array,boolean,integer`.

```
$data = array(
    "first_name" => "syed mohammad hussain",
    "last_name" => "naqvi",
);
$res->setData($data);
```

### ::setErrors

[](#seterrors)

you can set your errors for response using this method accept `Error instance or null` data format.

```
//pass array of errors codes
$res->setErrors([1100, 1101, 1102, 1105]);

// pass errors code with text message
$res->setErrors([
    array("code" => 1100, "message" => "user not found!")
]);

// or you can use Error instance to manage better and more comfortable your errors
$errors = new Errors();
$errors->addErrorCode(1100);
$errors->addErrorCode(1101);
$errors->addErrorCode(1102);
$errors->addErrorCode(1105);

$res->setErrors($errors->getErrorsCodes());
```

### ::getData

[](#getdata)

return your setup response data.

```
$data = $res->getData();
```

### ::getStatus

[](#getstatus)

return response status boolean value.

```
$status = $res->getStatus();
```

### ::getErrors

[](#geterrors)

return your setup error from response instance.

```
$errors = $res->getErrors();
```

### ::toJson

[](#tojson)

in this method set header content-type to application/json for show json response

`header('Content-Type: application/json; charset=utf-8');`

using `exit()` to stop php process and `json_encode()` to encode data to json .

```
$res->toJson();
```

### ::toArray

[](#toarray)

return `array` of response object has `success|errors|data` arrays key

```
$response = $res->toArray();

$success =  $response["success"];
$data =  $response["data"];
$errors =  $response["errors"];
```

created by @smhnaqvi

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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

Unknown

Total

1

Last Release

791d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3da63afa96b48bc299e664faf86802e0a2620fea8a657c87bc03f501d7e9b491?d=identicon)[smhnaqvi](/maintainers/smhnaqvi)

---

Top Contributors

[![smhnaqvi](https://avatars.githubusercontent.com/u/22330581?v=4)](https://github.com/smhnaqvi "smhnaqvi (3 commits)")

### Embed Badge

![Health badge](/badges/smhnaqvi-json-response/health.svg)

```
[![Health](https://phpackages.com/badges/smhnaqvi-json-response/health.svg)](https://phpackages.com/packages/smhnaqvi-json-response)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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