Class Highlight\JsonRef


Class to decode JSON data that contains path-based references.

The language data file for highlight.js are written as JavaScript classes and therefore may contain variables. This allows for inner references in the language data. This kind of data can be converterd to JSON using the path based references. This class can be used to decode such JSON structures. It follows the conventions for path based referencing as used in dojox.json.ref form the Dojo toolkit (Javascript). A typical example of such a structure is as follows:

{ "name":"Kris Zyp", "children":[{"name":"Jennika Zyp"},{"name":"Korban Zyp"}], "spouse":{

"name":"Nicole Zyp",

}, "oldestChild":{"$ref":"#children.0"} }

Usage example:

$jr = new JsonRef(); $data = $jr->decode(file_get_contents("data.json")); echo $data->spouse->spouse->name; // echos 'Kris Zyp' echo $data->oldestChild->name; // echos 'Jennika Zyp'

Public Methods

Hide inherited methods

MethodDescriptionDefined By
decode() Decode JSON data that may contain path based references. Highlight\JsonRef

Method Details

decode() public method

Decode JSON data that may contain path based references.

public mixed decode ( $json )
$json string|object

JSON data string or JSON data object.

return mixed

The decoded JSON data.