Class to open, modify and write json objects in files.
Just include the json.php
file.
require 'src/json.php';
Alternatively, namespace and autoload it.
composer require dayjo/php-json-handler
Then use;
use Dayjo\JSON;
Basic usage includes auto saving, so you just modify the data and it saves!
<?php
$JSON = new JSON('config.json');
$config =& $JSON->data; // You could just do $config->data->name = ...
$config->name = 'dayjo';
$config->last_edited = time();
The optional second parameter to the JSON class allows you to turn off auto save, and make it so you have to run the save function manually for instance;
<?php
$JSON = new JSON('config.json', false);
$config =& $JSON->data;
$config->name = 'dayjo';
$JSON->save();