To JSONP conversion

@param   mixed   $data
@param   bool    $pretty    wether to make the json pretty
@param   string  $callback  JSONP callback
@return  string  formatted JSONP
970319
public function to_jsonp($data = null, $pretty = false, $callback = null)
	{
		$callback or $callback = \Input::param('callback');
		is_null($callback) and $callback = 'response';

		return $callback.'('.$this->to_json($data, $pretty).')';
	}
643102
public static function prettyJSON(
        $data,
        int $flags = \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES
    ): int {
        $string = (string)\json_encode($data, $flags);

        return Console::write($string);
    }
1061740
protected function prepareData($data)
    {
        $callback = function ($value) {
            return $value !== null && $value !== [] && $value !== '';
        };

        foreach ($data as &$value) {
            if (is_array($value)) {
                $value = $this->prepareData($value);
            }
        }
        return array_filter($data, $callback);
    }
598413
public static function encode($data): string
    {
        $json = json_encode($data);

        if ($json === false) {
            $errNo = json_last_error();
            $msg = json_last_error_msg();
            throw new Exception("Unable to encode data to JSON, error ({$errNo}): {$msg}", $errNo);
        }

        return $json;
    }
706793
public function toJson($options = 0, $includeMetaData = false, $nestedInclude = true, $callback = null)
	{
		$data = $this->toArray($includeMetaData, $nestedInclude, $callback);
		return json_encode($data, $options);
	}
279165
public static function post($urls, $data = null, callable $callback = null)
    {
        return static::make('post', $urls, $data, $callback);
    }
1085119
public static function put($urls, $data = null, callable $callback = null)
    {
        return static::make('put', $urls, $data, $callback);
    }
462468
private function jsonResponse($data)
    {
        $response = new Response(json_encode($data));
        $response->headers->set('Content-Type', 'application/json');
        return $response;
    }
315694
public static function json_decode($data)
    {
        $data_json = @json_decode($data, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(
                sprintf('An error occurred while trying to decode JSON data [code "%s"]!', json_last_error())
            );
        } else {
            $data = $data_json;
        }
        return $data;
    }
5147
public static function retJSON($response = null, $prettyPrint = false)
    {
        $options = $prettyPrint ? JSON_PRETTY_PRINT : 0;

        return json_encode($response, $options);
    }
1263794
static public function fromArrayCallback(array $data, callable $callback) {
		$ret = new FormOptions();
		foreach ( $data as $item ){
			list($value, $text) = $callback($item);
			$ret->add($value, $text);
		}
		return $ret;
	}
1311964
protected function urlSafeDecode($data, $asJson = true)
    {
        if (!$asJson) {
            return \base64_decode(\strtr($data, '-_', '+/'));
        }

        $data = \json_decode(\base64_decode(\strtr($data, '-_', '+/')));
        $this->validateLastJson();

        return $data;
    }
1204970
public function plain($view, array $data, $callback=null)
    {
        return $this->send(['text'=>$view], $data, $callback);
    }
103946
public static function reformatData($data, $sourceFormat = null, $targetFormat = null)
    {
        if (is_null($data) || ($sourceFormat == $targetFormat)) {
            return $data;
        }

        switch ($sourceFormat) {
            case DataFormats::JSON:
                if (is_array($data)) {
                    $data = self::jsonEncode($data);
                }
                switch ($targetFormat) {
                    case DataFormats::XML:
                        return static::jsonToXml($data);

                    case DataFormats::CSV:
                        return static::jsonToCsv($data);

                    case DataFormats::PHP_ARRAY:
                        return static::jsonToArray($data);
                }
                break;

            case DataFormats::XML:
                switch ($targetFormat) {
                    case DataFormats::JSON:
                        return static::xmlToJson($data);

                    case DataFormats::CSV:
                        return static::xmlToCsv($data);

                    case DataFormats::PHP_ARRAY:
                        return static::xmlToArray($data);
                }
                break;

            case DataFormats::CSV:
                switch ($targetFormat) {
                    case DataFormats::JSON:
                        return static::csvToJson($data);

                    case DataFormats::XML:
                        return static::csvToXml($data);

                    case DataFormats::PHP_ARRAY:
                        return static::csvToArray($data);
                }
                break;

            case DataFormats::PHP_ARRAY:
                switch ($targetFormat) {
                    case DataFormats::JSON:
                        //  Symfony Response object automatically converts this.
                        return $data;
//                        return static::arrayToJson( $data );

                    case DataFormats::XML:
                        return static::arrayToXml($data);

                    case DataFormats::CSV:
                        return static::arrayToCsv($data);

                    case DataFormats::TEXT:
                        return json_encode($data);

                    case DataFormats::PHP_ARRAY:
                        return $data;
                }
                break;

            case DataFormats::PHP_OBJECT:
                switch ($targetFormat) {
                    case DataFormats::JSON:
                        //  Symfony Response object automatically converts this.
                        return $data;
//                        return static::arrayToJson( $data );

                    case DataFormats::XML:
                        return static::arrayToXml($data);

                    case DataFormats::CSV:
                        return static::arrayToCsv($data);

                    case DataFormats::TEXT:
                        return json_encode($data);

                    case DataFormats::PHP_ARRAY:
                        return $data;
                }
                break;

            case DataFormats::RAW:
            case DataFormats::TEXT:
                // treat as string for the most part
                switch ($targetFormat) {
                    case DataFormats::JSON:
                        return json_encode($data);

                    case DataFormats::XML:
                        $root = config('df.xml_response_root', 'dfapi');

                        return '<?xml version="1.0" ?>' . "<$root>$data</$root>";

                    case DataFormats::CSV:
                    case DataFormats::TEXT:
                        return $data;

                    case DataFormats::PHP_ARRAY:
                        return [$data];
                }
                break;
        }

        return false;
    }
484405
public function jsonp($input, $callback)
    {
        return $this
            ->withHeader('Content-Type', 'application/javascript')
            ->write(sprintf('%s(%s);', $callback, json_encode($input)));
    }
459727
public static function putJson(string $filename, array $data, bool $prettyPrint = true): void
    {
        if (!Str::endsWith($filename, '.json')) {
            $filename .= '.json';
        }
        $options = JSON_UNESCAPED_SLASHES;
        if ($prettyPrint) {
            $options += JSON_PRETTY_PRINT;
        }
        $data = json_encode($data, $options);
        self::put($filename, $data);
    }
933471
protected function jsonResponse($data)
    {
        /** @var \Magento\Framework\Controller\Result\Json $resultJson */
        $resultJson = $this->resultJsonFactory->create();
        $resultJson->setHeader('Content-type', 'application/json', true);
        $resultJson->setData($data);
        return $resultJson;
    }