dayjo/php-json-handler

Class for opening and writing to json files easily

v1.0.16 2018-02-28 17:08 UTC

This package is not auto-updated.

Last update: 2024-04-28 02:32:32 UTC


README

Class to open, modify and write json objects in files.

Installation (without composer)

Just include the json.php file.

require 'src/json.php';

Alternatively, namespace and autoload it.

Installation (with composer)

composer require dayjo/php-json-handler

Then use;

use Dayjo\JSON;

Usage

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();

Options

Auto Save

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();