Developer’s manual

Reading JSON data using the JSON connector service is a simple task. The first step is to get the proper service object:

$services = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::findService('connector', 'json');
if ($services === false) {
        // Issue an error
} else {
        $connector = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService('connector', 'json');

On the first line, you get a list of all services that are of type “connector” and subtype “json”. If the result if false, it means no appropriate services were found and you probably want to issue an error message.

On the contrary you are assured that there’s at least one valid service and you can get an instance of it by calling \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceService().

The next step is simply to call the appropriate method from the API – with the right parameters – depending on which format you want to have in return. For example:

$parameters = [
         'uri' => '',
         'encoding' => 'utf-8',
$data = $connector->fetchArray($parameters);

This will return a PHP array from the decoded JSON data. The fetchRaw() method will return the JSON data as a string.

The fetchXML() method returns a XML version of the PHP array transformed using \TYPO3\CMS\Core\Utility\GeneralUtility::array2xml.