<commit_before>package render

import (
	"encoding/json"
	"net/http"

	"github.com/Sirupsen/logrus"
)

var jsonContentType = "application/json; charset=utf-8"

type apiResponseBody struct {
	responseMeta `json:"meta,omitempty"`
	Payload      interface{} `json:"payload,omitempty"`
}

type responseMeta struct {
	Status int   `json:"status,omitempty"`
	Error  error `json:"error,omitempty"`
}

func Error(w http.ResponseWriter, status int, err error) {
	w.Header().Set("Content-Type", jsonContentType)
	w.WriteHeader(status)

	body := apiResponseBody{
		responseMeta: responseMeta{
			Status: status,
			Error:  err},
		Payload: nil}

	handleBody(w, body)
}

func JSON(w http.ResponseWriter, status int, payload interface{}) {
	w.Header().Set("Content-Type", jsonContentType)
	w.WriteHeader(status)

	body := apiResponseBody{
		responseMeta: responseMeta{
			Status: status},
		Payload: payload}

	handleBody(w, body)
}

func JSONWithHeaders(w http.ResponseWriter, status int, headers map[string]string, payload interface{}) {
	h := w.Header()
	h.Set("Content-Type", jsonContentType)
	for k, v := range headers {
		h.Set(k, v)
	}
	w.WriteHeader(status)

	body := apiResponseBody{
		responseMeta: responseMeta{
			Status: status},
		Payload: payload}

	handleBody(w, body)
}

func handleBody(w http.ResponseWriter, body apiResponseBody) {
	encoded, err := json.Marshal(body)<commit_msg>Pretty print all json responses<commit_after>package render

import (
	"encoding/json"
	"net/http"

	"github.com/Sirupsen/logrus"
)

var jsonContentType = "application/json; charset=utf-8"

type apiResponseBody struct {
	responseMeta `json:"meta,omitempty"`
	Payload      interface{} `json:"payload,omitempty"`
}

type responseMeta struct {
	Status int   `json:"status,omitempty"`
	Error  error `json:"error,omitempty"`
}

func Error(w http.ResponseWriter, status int, err error) {
	w.Header().Set("Content-Type", jsonContentType)
	w.WriteHeader(status)

	body := apiResponseBody{
		responseMeta: responseMeta{
			Status: status,
			Error:  err},
		Payload: nil}

	handleBody(w, body)
}

func JSON(w http.ResponseWriter, status int, payload interface{}) {
	w.Header().Set("Content-Type", jsonContentType)
	w.WriteHeader(status)

	body := apiResponseBody{
		responseMeta: responseMeta{
			Status: status},
		Payload: payload}

	handleBody(w, body)
}

func JSONWithHeaders(w http.ResponseWriter, status int, headers map[string]string, payload interface{}) {
	h := w.Header()
	h.Set("Content-Type", jsonContentType)
	for k, v := range headers {
		h.Set(k, v)
	}
	w.WriteHeader(status)

	body := apiResponseBody{
		responseMeta: responseMeta{
			Status: status},
		Payload: payload}

	handleBody(w, body)
}

func handleBody(w http.ResponseWriter, body apiResponseBody) {
	encoded, err := json.MarshalIndent(body, "", "    ")
{'fraction_non_alphanumeric': 0.1326676176890157, 'fraction_numerical': 0.0007132667617689016, 'mean_word_length': 5.032258064516129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '572622', 'n_tokens_mistral': 958, 'n_tokens_neox': 909, 'n_words': 219}