PHP code example of jpbassalot / jsonapi

1. Go to this page and download the library: Download jpbassalot/jsonapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jpbassalot / jsonapi example snippets




use Jpbassalot\JsonApi;

// A directory containing JSON files
$dir = 'json';

$reports = new JsonApi($dir, 9);

$all_files = $reports->getFiles();

$search = isset($_GET['search']) ? htmlspecialchars($_GET['search'], ENT_QUOTES, 'UTF-8') : '';

/**
* JSON Example:
 * {
 *  "title": "My Title",
 *  "property1": "Property 1",
 *  "property2": "Property 2",
 *  "property3": "Property 3",
 *  "nested": {
 *      "property1": "Nested Property 1",
 *      "property2": "Nested Property 2"
 * }
 */
if ($search) {
    $result = $reports->searchFilesData($search, ['title', 'property1', 'property2', 'property3', 'nested.property1', 'nested.property2'], $all_files);
} else {
    $result = $reports->getFilesData($all_files);
}

echo $reports->sendJson($result, $all_files);