Changeset 781 for trunk


Ignore:
Timestamp:
Feb 26, 2023 9:21:30 PM (14 months ago)
Author:
anonymous
Message:

Improve pretty json output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r774 r781  
    2929 * Print variable dump.
    3030 *
    31  * @param  mixed    $var        The variable to dump.
    32  * @param  bool     $display    Print the dump in <pre> tags or hide it in html comments (non-CLI only).
    33  * @param  bool     $dump_method   Dump method. See SC_DUMP_* constants.
    34  * @param  string   $file       Value of __FILE__.
    35  * @param  string   $line       Value of __LINE__
     31 * @param  mixed    $var            The variable to dump.
     32 * @param  bool     $display        Print the dump in <pre> tags or hide it in html comments (non-CLI only).
     33 * @param  const    $dump_method    Dump method. See SC_DUMP_* constants.
     34 * @param  string   $file           Value of __FILE__.
     35 * @param  string   $line           Value of __LINE__
    3636 */
    3737define('SC_DUMP_PRINT_R', 0);
     
    116116*
    117117* @access   public
    118 * @param    mixed   $var        The variable to dump.
    119 * @param    bool    $serialize  If true, remove line-endings. Useful for logging variables.
    120 * @return   string              The dumped variable.
     118* @param    mixed   $var            The variable to dump.
     119* @param    bool    $serialize      If true, remove line-endings. Useful for logging variables.
     120* @param    const   $dump_method    Dump method. See SC_DUMP_* constants.
     121* @return   string                  The dumped variable.
    121122* @author   Quinn Comendant <quinn@strangecode.com>
    122123*/
     
    162163
    163164    case SC_DUMP_JSON:
    164         $d = json_encode($var, JSON_PRETTY_PRINT);
    165         break;
     165        $json_flags = $serialize ? 0 : JSON_PRETTY_PRINT;
     166        return json_encode($var, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | $json_flags);
    166167    }
    167168    return $serialize ? preg_replace('/\s+/m' . $app->getParam('preg_u'), ' ', $d) : $d;
Note: See TracChangeset for help on using the changeset viewer.