Skip to table dataSkip to menuSkip to searchHotkeys reference
Sometimes it's difficult to control how much information is sent in response to an API request.
The script below, run from a PHP-equipped server or workstation, can filter the response data.
It reads the response in to an array, filters it, and converts the minimized result to JSON.
It operates recursively and can be modified to filter data from differently structured arrays.

//This script shows how to filter a large result set, or response, returned from an API.
//Commenting and uncommenting print_r, var_dump, print, echo lines makes it easy to examine responses in detail.
//It's currently configured for the data returned from the uncommented $url variable on line 13.
//Change the $url to a different API. The print command on line 26 makes it easy to examine the response.
//The search function on line 29 filters the response array by variables supplied via $_GET["VARIABLE"].
//The walk_recursive_remove function on line 43 removes key-value pairs with empty values.
//The search_through_array function on line 61 extracts a single record from the array.

$manufacturerid = $_GET["ManufacturerId"];
//$manufacturername = $_GET["ManufacturerName"];
$name = $_GET["Name"];
$url = "";
//$url = ";capital;region;subregion;population;area;currencies";
//$url = "";
//$url = "";
//$url = "";
//$url = "";
$curl = curl_init( $url );
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$json_response = curl_exec($curl);
$result = json_decode($json_response, TRUE);
//print_r ($result);
print("<pre>".print_r($result, TRUE)."</pre>");
$arr = $result;
function search($array, $key, $value) {$results = array();
if (is_array($array)) {
if (isset($array[$key]) && $array[$key] == $value) {$results[] = $array;}
foreach ($array as $subarray) { $results = array_merge($results,search($subarray, $key, $value));}}
return $results;}
//$res = search($arr, 'ManufacturerId',1152);
$res = search($arr, 'ManufacturerId',"$manufacturerid");
//$res = search($arr, 'ManufacturerName','MERCEDES-BENZ OF NORTH AMERICA, INC.');
//$res = search($arr, 'ManufacturerName',"$manufacturername");
//$res = search($arr, 'Name','ORG10626');
//$res = search($arr, 'Name',"$name");
//print_r ($res);
//print("<pre>".print_r($res, TRUE)."</pre>");
function walk_recursive_remove (array $array, callable $callback) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = walk_recursive_remove($v, $callback);
} else {
if ($callback($v, $k)) {
unset($array[$k]); }}}
return $array;
$arr = $res;
$result = walk_recursive_remove($arr, function ($value) {
return $value === null || $value === '';
//print_r ($result);
print("<pre>".print_r($result, TRUE)."</pre>");
//$data = $res;
$data = $result;
function search_through_array($search,array $lists){
foreach ($lists as $key => $value) {
array_walk_recursive($value, function($v, $k) use($search ,$key,$value,&$val){
if(strpos($v, $search) !== false ) $val[$key]=$value;});
if(strpos($value, $search) !== false ) $val[$key]=$value;}}
return $val;}catch (Exception $e) {return false;}
$new = search_through_array("$name",$data);
$Package = json_encode($new,TRUE);
echo $Package;