Club Penguin Wiki:$cp Library/JSON

The $cp JSON library allows to easily get JSON resources from Club Penguin. The files that can be loaded must be available in the JSONP format (see the main and the cross-domain sections in Club Penguin Wiki:JSON). The set of functions is accessible via.

Accessing loaded JSON data
The loaded JSON data is stored in the object. The data can be accessed in the following way: $cp.json.val[lang][file] Where: Whenever a JSON request of a Club Penguin file that has already loaded is executed, the available value will automatically be used
 * file- a string, the JSON's file name
 * lang- a string, the language version of the file. Available languages:

Loading JSON
For getting a JSON file, the  needs to be called with a single parameter- and object containing the info about the requested file: The object requires 1 to 3 properties:
 * file- a string, the JSON's file name
 * lang (optional)- a string, the language version of the file (if available)
 * success (optional)- a function, executed as the resource has loaded. An argument can be used, which allows to automatically work with the returned JSON data, rather than accessing its value via

Loading multiple resources
For loading muiple Club Penguin resources at once, the  function can be used. It works similarly to the  function, but instead of using a single parameter, it uses two:
 * 1) An array of objects (same as the object used in, but without the success property).
 * 2) A callback function (optional) when all resources from the array have loaded. No data is passed to the function as an argument, and if some JSON values are required, they must be retreived via  first.