public static function jsonEncode($data)
    {
        $json = json_encode($data);
        // if json_encode failed
        if ($json === false) {
            self::jsonLastError();
        }
        return $json;
    }
public static function jsonEncode($data)
    {
        $json = json_encode($data);
        // if json_encode failed
        if ($json === false) {
            self::jsonLastError();
        }
        return $json;
    }
public static function jsonEncode ( $ data ) { $ json = json_encode ( $ data ) ; // if json_encode failed if ( $ json === false ) { self :: jsonLastError ( ) ; } return $ json ; }
Encode as JSON and throw error if fails

@param mixed $data - data to encode

@static

@return string - json string
@throws \Exception if json decode fails with message about why
Encode as JSON and throw error if fails