LaravelPackages.net
Acme Inc.
Toggle sidebar
jlozanomaltos/json-reducer

An array size reducer (for JSON output purposes) using Models, Collections, Arrays

51
9
v1.0.9
About jlozanomaltos/json-reducer

jlozanomaltos/json-reducer is a Laravel package for an array size reducer (for json output purposes) using models, collections, arrays. It currently has 9 GitHub stars and 51 downloads on Packagist (latest version v1.0.9). Install it with composer require jlozanomaltos/json-reducer. Discover more Laravel packages by jlozanomaltos or browse all Laravel packages to compare alternatives.

Last updated

JsonReducer

What is it?

An array size reducer (for JSON output purposes) using Models, Collections, Arrays for Laravel/Lumen

It's basically an implementation of following: Smaller Serialized Data

Input example (Eloquent Model Array Visualization)

{
 "data": [
		{
			"id": 1,
			"name": "Jesús Emanuel",
			"lastname": "Lozano Maltos"
		},
		{
			"id": 2,
			"name": "Gilberto",
			"lastname": "Reyes Barrera"
		}
  ]
}

Output example (Array Visualization)

{
 "data": {
		{
			"id":[1, 2],
			"name": ["Jesús Emanuel", "Gilberto"],
			"lastname": ["Lozano Maltos", "Reyes Barrera"]
		}
  }
}

Installation

Require package using composer

composer require jlozanomaltos/json-reducer

Then just require the class (where you need it)

use JLozanoMaltos\JsonReducer\JsonReducer;

Example usage (laravel)

public function index()
{
	$users = User::all();
	return response()->json(JsonReducer::reduce($users));
}
Comments