Josh Randall Josh Randall - 9 months ago 105
JSON Question

Cakephp read and write json files.

I am new to cakephp. I am trying to save json output as a file in webroot. I would also like read the file into a array.

I know we could output array as json object using json_encode($array). But I am stuck creating and reading json files into an array.

I appreciate any help.

$json = '{"key":"value"}';
$file = new File('/path/to/file', true);
$file = new File('/path/to/file');
$json = $file->read(true, 'r');
$json2array = json_decode($json);