<commit_before><?php

class JsonExport
{
    public function handler($data, $options = array())
    {
		if ($options['scope'] === 'Attribute') {
			return $this->__attributeHandler($data, $options);
		} else {
			return $this->__eventHandler($data, $options);
		}
    }

	private function __attributeHandler($attribute, $options = array())
	{
		$attribute = array_merge($attribute['Attribute'], $attribute);
		unset($attribute['Attribute']);
		if (isset($attribute['Object']) && empty($attribute['Object']['id'])) {
			unset($attribute['Object']);
		}
		if (isset($attribute['AttributeTag'])) {
			$attributeTags = array();
			foreach ($attribute['AttributeTag'] as $tk => $tag) {
				$attribute['Tag'][$tk] = $attribute['AttributeTag'][$tk]['Tag'];
			}
			unset($attribute['AttributeTag']);
			unset($attribute['value1']);
			unset($attribute['value2']);
		}
		return json_encode($attribute);
	}

    public function header($options = array())
    {
		return '{"response": {"Attribute": [';
    }

    public function footer()
    {
		return ']}}' . PHP_EOL;
    }

    public function separator()
    {
        return ',';
    }

}<commit_msg>new: [API] JSON export library updated to support both attribute and event level conversions.<commit_after><?php

class JsonExport
{
	private $__converter = false;

    public function handler($data, $options = array())
    {
		if ($options['scope'] === 'Attribute') {
			return $this->__attributeHandler($data, $options);
		} else {
			return $this->__eventHandler($data, $options);
		}
    }

	private function __eventHandler($event, $options = array()) {
		if ($this->__converter === false) {
			App::uses('JSONConverterTool', 'Tools');
			$this->__converter = new JSONConverterTool();
		}
		return json_encode($this->__converter->convert($event, false, true));
	}

	private function __attributeHandler($attribute, $options = array())
	{
		$attribute = array_merge($attribute['Attribute'], $attribute);
		unset($attribute['Attribute']);
		if (isset($attribute['Object']) && empty($attribute['Object']['id'])) {
			unset($attribute['Object']);
		}
		if (isset($attribute['AttributeTag'])) {
			$attributeTags = array();
			foreach ($attribute['AttributeTag'] as $tk => $tag) {
				$attribute['Tag'][$tk] = $attribute['AttributeTag'][$tk]['Tag'];
			}
			unset($attribute['AttributeTag']);
			unset($attribute['value1']);
			unset($attribute['value2']);
		}
		return json_encode($attribute);
	}

    public function header($options = array())
    {
		if ($options['scope'] === 'Attribute') {
			return '{"response": {"Attribute": [';
		} else {
			return '{"response": [';
		}
    }

    public function footer($options = array())
    {
		if ($options['scope'] === 'Attribute') {
			return ']}}' . PHP_EOL;
		} else {
			return ']}' . PHP_EOL;
		}

    }

    public function separator()
    {
        return ',';
    }

}
{'fraction_non_alphanumeric': 0.198326943185779, 'fraction_numerical': 0.0013942140118508191, 'mean_word_length': 4.189873417721519, 'pattern_counts': {'":': 5, '<': 5, '<?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': '1756301', 'n_tokens_mistral': 960, 'n_tokens_neox': 859, 'n_words': 172}