Grouper Documentation
Grouper Documentation
twitter youtube linkedin google-plus
Grouper: RSS manager, XML converter, website scraper
Web This Site

Grouper - Documentation


Getting Started: Free Download | Purchase | Install
Reference: Functions | Plugins | Themes
Etc.: Configure | Affiliates


JSON plugin

The JSON plugin converts JSON documents to RSS. It requires additional configuration to define the mapping between the JSON structure and RSS, and if the original data is to be altered, rather than simply copied into RSS elements as is, requires additional code to perform the alterations. A helper plugin is available to handle the configuration and extra processing needed for YouTube's JSON API.

Installation:
To use the JSON plugin, json.php and any helper plugins must be located in the "plugins" folder inside the folder containing grouper.php. This is their default location when Grouper Evolution is installed.

Loading the plugins:
To load the plugins, use code like the following. Note that the JSON plugin must be loaded before any helper plugins are loaded.

<?php
require_once '/YOUR/PATH/TO/grouper/grouper.php';
GrouperLoadPlugin('json.php');
GrouperLoadPlugin('HELPER-PLUGIN-FILENAME');
GrouperSourceURL('http://example.com/document.json');
GrouperShow('','CACHE-FILE-NAME');
?>

Helper Plugin Developer Technical Information

Helper plugins must set certain configuration options in the JSON plugin to define the mapping from the source JSON structure to RSS, and may also provide additional functions to process the data. We recommend using one of the helper plugins included with Grouper Evolution as a starting point and model when developing your own helper plugins.

The JSON to RSS mapping is defined by the "element-map" configuration setting. This setting is a nested array with the following structure. Note that pretty much everything is optional under most circumstances. If in doubt of whether you can omit something, try it out and see if it works: Paths to elements and attributes
Paths to source elements and attributes are specified using a subset of XPath syntax. Process and Process-Children Callback Functions
The prototype for "process" and "process-children" functions is:

function FunctionName($element_name, $source_data)

$element_name is the name of the RSS element being created. For "process" functions, $source_data is the contents of the source element. It does not include any child elements defined in the element map, but does include any child elements from the source data. For "process-children" functions, $source_data is the fully constructed child elements.

The return value of the "process" and "process-children" functions will take the place of $source_data in the content of the RSS element that is being created.