$sanitizerjson()

Sanitize value to formatted and readable JSON string

If you do not need formatted/readable JSON string then use PHP’s json_encode() function instead.

Available since version 3.0.256.

Usage

// basic usage
$false = $sanitizer->json(mixed $value);

// usage with all arguments
$false = $sanitizer->json(mixed $value, array $options = []);

Arguments

NameType(s)Description
$valuemixed
$options (optional)array
  • pretty (bool): Make it readable/pretty Default:true
  • escaped (bool): Escape unicode, slashes and line terminators? Default:true
  • throw (bool): Throw \JsonException on errors? Default:false 3.0.269+
  • depth (int): Maximum nesting depth when test decoding Default:512 3.0.269+

Return value

false string

Returns JSON string on success, boolean false on error.

Exceptions

Method can throw exceptions on error:

  • \JsonException - If throw option is true and JSON encoding or decoding fails.


$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.269