Return $data encoded as JSON.

@param mixed $response    The response
@param bool  $prettyPrint If true the JSON will be pretty printed

@return string JSON encoded $response
5147
public static function retJSON($response = null, $prettyPrint = false)
    {
        $options = $prettyPrint ? JSON_PRETTY_PRINT : 0;

        return json_encode($response, $options);
    }
510908
public static function objectToJson($object = false, $pretty = false) {

        if ($object && Validate::isObject($object)) {

            $array = self::objectToArray($object);
            return self::arrayToJson($array, $pretty);
        }

        return false;
    }
716022
def maybe_print_as_json(opts, data, page_info=None):
    """"""
    if opts.output not in ("json", "pretty_json"):
        return False

    root = {"data": data}

    if page_info is not None and page_info.is_valid:
        meta = root["meta"] = {}
        meta["pagination"] = page_info.as_dict(num_results=len(data))

    if opts.output == "pretty_json":
        dump = json.dumps(root, indent=4, sort_keys=True)
    else:
        dump = json.dumps(root, sort_keys=True)

    click.echo(dump)
    return True
1025907
private function convert_body_string_to_json( $response ) {
		if ( $this instanceof Gitea_API || $this instanceof Bitbucket_API || $this instanceof Bitbucket_Server_API ) {
			$body = wp_remote_retrieve_body( $response );
			if ( null === json_decode( $body ) ) {
				$response['body'] = json_encode( $body );
			}
		}

		return $response;
	}
875518
private function wrapResponse(Response $response, $result = null, string $output = ''): Response
    {
        if ($result instanceof Response) {
            if (!empty($output) && $result->getBody()->isWritable()) {
                $result->getBody()->write($output);
            }

            return $result;
        }

        if (is_array($result) || $result instanceof \JsonSerializable) {
            $response = $this->writeJson($response, $result);
        } else {
            $response->getBody()->write($result);
        }

        //Always glue buffered output
        $response->getBody()->write($output);

        return $response;
    }
576214
public static function json($mData, $bPretty = FALSE) {
		$iArg = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
		if ($bPretty) {
			$iArg = $iArg | JSON_PRETTY_PRINT;
		}
		return json_encode($mData, $iArg);
	}
1094840
public static function prettyJSONPrint($json)
    {
        $result = '';
        $level = 0;
        $in_quotes = false;
        $in_escape = false;
        $ends_line_level = null;
        $json_length = strlen($json);

        for ($i = 0; $i < $json_length; $i++) {
            $char = $json[$i];
            $new_line_level = null;
            $post = "";
            if ($ends_line_level !== null) {
                $new_line_level = $ends_line_level;
                $ends_line_level = null;
            }
            if ($in_escape) {
                $in_escape = false;
            } else {
                if ($char === '"') {
                    $in_quotes = !$in_quotes;
                } else {
                    if (!$in_quotes) {
                        switch ($char) {
                            case '}':
                            case ']':
                                $level--;
                                $ends_line_level = null;
                                $new_line_level = $level;
                                break;

                            case '{':
                            case '[':
                                $level++;
                            case ',':
                                $ends_line_level = $level;
                                break;

                            case ':':
                                $post = " ";
                                break;

                            case " ":
                            case "\t":
                            case "\n":
                            case "\r":
                                $char = "";
                                $ends_line_level = $new_line_level;
                                $new_line_level = null;
                                break;
                        }
                    } else {
                        if ($char === '\\') {
                            $in_escape = true;
                        }
                    }
                }
            }
            if ($new_line_level !== null) {
                $result .= "\n" . str_repeat("\t", $new_line_level);
            }
            $result .= $char . $post;
        }

        return $result;
    }
683532
protected function getResponseAsJson( ResponseInterface $response ) {
        if( $response->hasHeader('Content-Type') ) {
            $typeHeader = $response->getHeader('Content-Type');
            $contentType = array_shift($typeHeader);

            if( stripos( $contentType, 'application/json' ) === 0 ) {
                return json_decode($response->getBody(), false);
            }
        }

        return null;
    }
462468
private function jsonResponse($data)
    {
        $response = new Response(json_encode($data));
        $response->headers->set('Content-Type', 'application/json');
        return $response;
    }
978145
private function processHttpResponse($response)
    {
        if ($response === null) {
            return null;
        }

        switch ($this->fakeType) {
            case 'pngb64':
                $base64 = base64_encode($response->getBody());
                return 'data:image/png;base64,' . $base64;
            case 'object': // 'object' not supported yet, we return array instead.
            case 'array':
                return json_decode($response->getBody(), true);
            default:
                return $response->getBody()->__toString();
        }
    }
524697
protected function getUnserializedData(Response $response, $responseFormat)
    {
        return UnserializerBuilder::create($responseFormat)->unserialize(
            $response->getBody()->getContents()
        );
    }
530753
function(response) {
    var prettyJson = JSON.stringify(response, null, '\t').replace(/\n/g, '<br>');
    $('.response_body', $(this.el)).html(_.escape(prettyJson));
  }
1307202
def json_pretty_print(s):
    ''''''
    s = json.loads(s)
    return json.dumps(s,
                      sort_keys=True,
                      indent=4,
                      separators=(',', ': '))
1292541
protected function decodeData(ResponseObject $response)
    {
        $resultArray = json_decode($response->getBody(), true);
        if ($resultArray === null) {
            throw new JsonException('Failed to decode response', json_last_error());
        }

        return $resultArray;
    }
918753
public function jsonEncode($data, $prettyPrint)
    {
        try {
            $data = json_encode($data, (($prettyPrint) ? JSON_PRETTY_PRINT : 15));
        } catch (\Exception $e) {
            if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
                throw $e->getPrevious() ?: $e;
            }

            throw $e;
        }

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(json_last_error_msg());
        }

        return $data;
    }
1140721
public static function encode($data, $prettyPrint = true)
    {
        $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;

        $useNative = self::$useNativePrettyPrint && defined('JSON_PRETTY_PRINT') && defined('JSON_UNESCAPED_SLASHES');
        if ($prettyPrint && $useNative) {
            $options = $options | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;
        }

        $json = json_encode($data, $options);
        if ($prettyPrint && !$useNative) {
            $json = self::prettyPrint($json);
        }

        return $json;
    }
688528
def data_json(self, pretty=False):
        """"""
        if pretty:
            return json.dumps(self.data, sort_keys=True, indent=4, separators=(',', ': '))
        else:
            return json.dumps(self.data)