mod_json

This module provides methods to convert from and to JSON ( JavaScript Object Notation. ) Generally you just use the PHP json_encode() and json_decode() methods directly in PINP. However if for some reason these functions aren't available, this module provides a backup. In addition it has one extra method: indent() - which allows you to pretty-print a json string.

JSON::encode and JSON::decode accept a behaviour parameter, which can have one of the following values or a binary OR combination of them:

SERVICES_JSON_LOOSE_TYPELoose typing. When parsing JSON objects this creates a PHP associative array ( or hash ) instead.
SERVICES_JSON_SUPPRESS_ERRORSError suppresion. Values which can't be encoded to JSON will appear as NULL instead.

methods

(string)JSON::encodeEncode an array to a JSON string.
(mixed)JSON::decodeDecode a JSON string to an array.
(string)JSON::indentIndents a JSON string to a more readable format.

JSON::encode

(string) JSON::encode( $var, $use=0 )

(mixed)$varThe variable to convert to a JSON string.
(int)$useBehavior flags, see the list at the top.

Returns a JSON encoded string representing the input variable.

JSON::decode

(array) JSON::decode( $str, $use=0 )

(string)$strThe JSON string to convert to a PHP variable.
(int)$useBehavior flags, see the list at the top.

Parses the JSON string and returns its PHP equivalent.

JSON::indent

(string) JSON::indent( $str, $newLine="\n", $indentStr="\t" )

(string)$strThe variable to convert to a JSON string.
(string)$newLineThe string to use for each new line.
(string)$indentStrThe string to use to indent each level.

Returns a formatted JSON string with one entry per line and indentation.