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"}],
    "name":"Nicole Zyp",

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'
  • todo In Highlight.php 10.x, mark this class final with a keyword.
  • since has been marked as final
  • final
  • internal
Cloneable Instantiable
public decodeRef ( $json )

Decode JSON data that may contain path based references.

  • return void
private $paths

Array to hold all data paths in the given JSON data.

  • var array
private getPaths ( $s , $r = '#' )

Recurse through the data tree and fill an array of paths that reference
the nodes in the decoded JSON data structure.

  • return void
private resolvePathReferences ( $s , $limit = 20 , $depth = 1 )

Recurse through the data tree and resolve all path references.

  • return void
© 2021 Bruce Wells
Search Namespaces \ Classes