<commit_before><?php
/**
 * Mime Type: application/json
 * @author <NAME> <<EMAIL>>
 */

namespace Httpful\Handlers;

class JsonHandler extends MimeHandlerAdapter
{
    private $decode_as_array = false;

    public function init(array $args)
    {
        $this->decode_as_array = !!(array_key_exists('decode_as_array', $args) ? $args['decode_as_array'] : false);
    }

    /**
     * @param string $body
     * @return mixed
     */
    public function parse($body)
    {
        if (empty($body))
            return null;
        $parsed = json_decode($body, $this->decode_as_array);
        if (is_null($parsed))
            throw new \Exception("Unable to parse response as JSON");
        return $parsed;
    }
<commit_msg>Remove UTF-8 BOM from response, if it exists<commit_after><?php
/**
 * Mime Type: application/json
 * @author <NAME> <<EMAIL>>
 */

namespace Httpful\Handlers;

class JsonHandler extends MimeHandlerAdapter
{
    private $decode_as_array = false;

    public function init(array $args)
    {
        $this->decode_as_array = !!(array_key_exists('decode_as_array', $args) ? $args['decode_as_array'] : false);
    }

    /**
     * @param string $body
     * @return mixed
     */
    public function parse($body)
    {
        if (empty($body))
            return null;

        if ( substr($body,0,3) == "\xef\xbb\xbf" )
            $body = substr($body,3);

        $parsed = json_decode($body, $this->decode_as_array);
        if (is_null($parsed))
            throw new \Exception("Unable to parse response as JSON");
        return $parsed;
    }

{'fraction_non_alphanumeric': 0.13869537682077265, 'fraction_numerical': 0.00253324889170361, 'mean_word_length': 2.6155606407322654, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7133231', 'n_tokens_mistral': 496, 'n_tokens_neox': 496, 'n_words': 116}