<commit_before>import datetime
import json

from django.conf import settings
from django.http import HttpResponse


class JsonResponse(HttpResponse):
    """
    Returns a HTTP response with JSON content type. Performs automatic
    serialization if given an object.
    """

    def __init__(self, obj=None, **kwargs):

        # Perform JSON serialization
        if obj:

            # Pretty print in debug mode
            indent_level = 4 if settings.DEBUG else 0

            # datetime parsing
            datetime_handler = lambda o: o.isoformat() if isinstance(o, datetime.datetime) else None

            # Dump with Python's JSON module
            content = json.dumps(obj, indent=indent_level, default=datetime_handler)

        else:
            content = ''

        # Content type and status code for the response
        content_type = 'application/json; charset=%s' % settings.DEFAULT_CHARSET
        status_code = kwargs.get('status', 200)

        # Return response as JSON
        super(JsonResponse, self).__init__(
            content,
            content_type=content_type,
            status=status_code
        )
<commit_msg>Fixed an issue where a root object evaluating to False wasn't serialized properly in JsonResponse.<commit_after>import datetime
import json

from django.conf import settings
from django.http import HttpResponse


class JsonResponse(HttpResponse):
    """
    Returns a HTTP response with JSON content type. Performs automatic
    serialization if given an object.
    """

    def __init__(self, obj=None, **kwargs):

        # Perform JSON serialization
        if obj is not None:

            # Pretty print in debug mode
            indent_level = 4 if settings.DEBUG else 0

            # datetime parsing
            datetime_handler = lambda o: o.isoformat() if isinstance(o, datetime.datetime) else None

            # Dump with Python's JSON module
            content = json.dumps(obj, indent=indent_level, default=datetime_handler)

        else:
            content = ''

        # Content type and status code for the response
        content_type = 'application/json; charset=%s' % settings.DEFAULT_CHARSET
        status_code = kwargs.get('status', 200)

        # Return response as JSON
        super(JsonResponse, self).__init__(
            content,
            content_type=content_type,
            status=status_code
        )

{'fraction_non_alphanumeric': 0.068304872969596, 'fraction_numerical': 0.004164931278633903, 'mean_word_length': 2.3688639551192145, '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': '7425203', 'n_tokens_mistral': 614, 'n_tokens_neox': 579, 'n_words': 207}