Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meadsteve/jsoner
Small utility class to help out with converting PHP objects to json.
https://github.com/meadsteve/jsoner
Last synced: 5 days ago
JSON representation
Small utility class to help out with converting PHP objects to json.
- Host: GitHub
- URL: https://github.com/meadsteve/jsoner
- Owner: meadsteve
- Created: 2013-01-24T09:44:26.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-01-31T21:09:45.000Z (almost 12 years ago)
- Last Synced: 2024-10-11T03:11:14.276Z (about 1 month ago)
- Language: PHP
- Size: 133 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JSONer
======Small utility class to help out with converting PHP objects to json.
Example Usage
=========Basic usage is very straight forward:
```php
$jsonBuilder = new \MeadSteve\JSONer\JSONer();$dataToOutput = array(
'id' => "y76",
'requestedData' => $ComplexObject
);$outputString = $jsonBuilder->convertToJSON($dataToOutput);
```This assumes that you want to use php's default behaviour to encode the ComplexObject. If you wanted a bit more control then ideally you would implement the JsonSerializable in the class. However If this isn't an option you can provide handler functions to the JSONer object:
```php
$jsonBuilder->registerSerializeFunction('ComplexObject', function($Object) {
$moreSimpleObject = new stdClass();
$moreSimpleObject->propertyOne = $Object->getPropertyOne();
return $moreSimpleObject;
});
```