Write json to the response

@param mixed $data
@return Reponse
779885
public function writeJson($data)
    {
        $data = json_encode($data);

        $this->write($data);
        $this->addHeader("Content-Type", "application/json");

        return $this;
    }
227485
public function jsonResponse($data)
    {
        $this->_headers[] = 'Content-Type: application/json';

        if (!headers_sent()) {
            foreach ($this->_headers as $header) {
                header($header, true);
            }
        }
        echo json_encode($data);
    }
11885
public function create($data)
    {
        $response = $this->restClient->post($this->endpoint, $data);
        return $response['body'];
    }
843639
public function sendData($data)
    {
        $response = $this->gocardless->payments()->update($data['paymentId'], $data['paymentData']);

        return $this->response = new PaymentResponse($this, $response);
    }
32018
public static function createFromDecodedJsonResponse($data)
    {
        $stack_operations = [];
        if (isset($data['stack_operations']) && \is_array($data['stack_operations'])) {
            foreach ($data['stack_operations'] as $operation) {
                $stack_operations[] = StackOperation::createFromDecodedJsonResponse($operation);
            }
        }

        $stack = new self(
            $data['organization'],
            $data['name'],
            $stack_operations,
            [],
            new \DateTime($data['created'])
        );

        if (isset($data['stack_options']) && \is_array($data['stack_options'])) {
            $stack->setStackOptions($data['stack_options']);
        }

        if (isset($data['stack_variables']) && \is_array($data['stack_variables'])) {
            $stack->setStackVariables($data['stack_variables']);
        }

        if (isset($data['stack_expressions']) && \is_array($data['stack_expressions'])) {
            $stack_expressions = [];
            foreach ($data['stack_expressions'] as $expression) {
                $stack_expressions[] = StackExpression::createFromDecodedJsonResponse($expression);
            }

            $stack->setStackExpressions($stack_expressions);
        }

        return $stack;
    }
777918
private function dataToJson($data)
        {
            $cols = $this->getColumns($data);

            $rows = [];

            foreach ($data as $key => $row) {
                if ($key != 0 || !$this->_skipFirstRow) {
                    $c = [];

                    foreach ($row as $v) {
                        $c[] = ['v' => $v];
                    }

                    $rows[] = ['c' => $c];
                }
            }

            return json_encode(['cols' => $cols, 'rows' => $rows]);
        }
392781
public function sendJson($data)
	{
		if ($data === null) {
			$this->terminate();
		}else{
			$this->sendResponse(new JsonResponse($data));
		}
	}
539827
public function sendData($data)
    {
        $response = $this->braintree->transaction()->refund($data['transactionReference'], $data['amount']);

        return $this->createResponse($response);
    }
186208
public function encodeOutput($data)
    {
        // TODO - use HTTP_ACCEPT here ?
        //var_dump($_SERVER['HTTP_ACCEPT']);

        if ($_GET['format'] == 'xml') {
            throw $this->exception('only JSON format is supported', null, 406);
        }

        if ($_GET['format'] == 'json_pretty') {
            header('Content-type: application/json');
            echo json_encode($data, JSON_PRETTY_PRINT);
            return;
        }

        if ($_GET['format'] == 'html') {
            echo '<pre>';
            echo json_encode($data, JSON_PRETTY_PRINT);
            return;
        }

        header('Content-type: application/json');

        if ($data === null) {
            $data = array();
        }
        echo json_encode($data);
    }
378888
public function json( $data ) {
		$response = $this->response();
		$response = $response->withHeader( 'Content-Type', 'application/json' );
		$response = $response->withBody( Psr7\stream_for( wp_json_encode( $data ) ) );
		return $response;
	}
741183
public function sendData($data)
    {
        $response = $this->braintree->transaction()->submitForSettlement($data['transactionReference'], $data['amount']);

        return $this->createResponse($response);
    }
230911
public function sendData($data)
    {
        $response = $this->braintree->merchantAccount()->create($data);

        return $this->response = new Response($this, $response);
    }
971075
public function write($data)
    {
        $this->contentLength += strlen($data);
        $this->data .= $data;

        return $this;
    }
945985
public function write($data)
    {
        $dataLen            = strlen($data);
        $this->content      = substr($this->content, 0, $this->bytes_read) . $data . substr($this->content, $this->bytes_read + $dataLen);
        $this->bytes_read  += $dataLen;
        $this->lastModified = time();
        return $dataLen;
    }
392474
public function store($data)
    {
        $message = $this->client->post(
            sprintf('buckets/%d/message_boards/%d/messages.json', $this->bucket, $this->parent),
            [
                'json' => $data,
            ]
        );

        return new Message($this->response($message));
    }
427433
protected function returnJson($data, $httpStatus = 200)
    {
        header(HTTPToolkit::statusCodeHeader($httpStatus));
        Context::getInstance()->getResponse()->setContentHeader('application/json');
        $this->response = $this->getPsrResponse()->withBody(stream_for(json_encode($data)));
    }
501151
public function asJson(array $data)
    {
        $stream = StreamFactory::string(json_encode($data));
        return new Response($stream, self::OK, ['Content-Type' => 'application/json']);
    }