Data sanitation and return as JSON.

@since 2.0.0

@param mixed $default → default value

@return mixed → value, null or customized return value
559783
public function asJson($default = null)
    {
        return Validate::asJson($this->params[$this->key] ?? $this->params, $default);
    }
873666
public function get($key = null, $default = null)
	{
		$return = $this->data;

		if ($key !== null) {
			$keys = explode('.', $key);

			foreach ($keys as $key) {
				if (isset($return[(string) $key])) {
					$return = $return[$key];
				} else {
					$return = $default;
					break;
				}
			}
		}

		return $return;
	}
106122
public function getData($field=null,$default=null){
        if(is_null($field)){
            return $this->data;
        }
        $tmp=$this->data;
        foreach(explode(".",$field) as $f){
            if(!isset($tmp[$f])){
                return $default;
            }
            $tmp=$tmp[$f];
        }
        return $tmp;
    }
996455
public function data(string $key, $default = null)
    {
        if (is_null($this->data)) {
            return $default;
        }

        return data_get($this->data, $key, $default);
    }
690738
public function get_data($field = null, $default = null) {
		if($field === null) return $this->data;
		return array_key_exists($field, $this->data) ? $this->data[$field] : $default;
	}
80775
public function jsonSerialize()
    {
        $data = $this->getData();
        if (empty($data)) {
            return null;
        }
        foreach (array_keys(static::FOREIGN_KEYS) as $column) {
            $data[$column] = $this->__get($column);
        }
        return $data;
    }
569681
public function getJson() : ?string 
    {
        if ( ! $this->hasJson()) {
            $this->setJson($this->getDefaultJson());
        }
        return $this->json;
    }
1174843
public static function json($index = null, $default = null)
	{
		static::$json === null and static::hydrate_raw_input('json');
		return (func_num_args() === 0) ? static::$json : \Arr::get(static::$json, $index, $default);
	}
770278
public function getJson()
    {
        $dirty = $this->getDirty();
        if (count($dirty)) {
            $this->internal_original_value = $this->__toString();
        }

        return $this->internal_original_value;
    }
208298
public function correctToJSON(){
        $returnValue = null;

        try{
            $correctResponses = $this->getCorrectResponses();
            if(count($correctResponses)){
                $returnValue = taoQTI_models_classes_Matching_VariableFactory::createJSONVariableFromQTIData(
                    $this->getIdentifier()
                    , $this->getAttributeValue('cardinality')
                    , $this->getAttributeValue('baseType')
                    , $this->correctResponses
                );
            }
        }catch(Exception $e){

        }

        return $returnValue;
    }
373399
public function get($key, $default)
    {
        if (is_array($key)) {
            $key = implode('.', $key);
        }

        return Arr::get($this->json, $key, $default);
    }
563708
protected static function restGetSortField($default = false)
    {
        $sort = Request::getInstance()->query('_sort', false);
        if (!$sort) {
            return $default;
        }

        $sortDirection = substr($sort, 0, 1);
        if ($sortDirection == '+' || $sortDirection == '-') {
            return substr($sort, 1);
        }

        return $sort;
    }
1088952
public function get($key = '', $default = null)
    {
        $key = $this->getCompositeKey($key);
        if (empty($key)) {
            return $this->storage;
        }
        return ArrayHelper::getValue($this->storage, $key, $default);
    }
466906
public function getJsonProperty($property, $key = null, $default = null)
    {
        $instance =  $this->getJsonInstance($property);

        if ( $key !== null ) {
            return $instance->get( $key, $default );
        }

        return $instance;
    }
893497
public function mapToJSON(){
        $returnValue = null;

        $mapping = $this->getMapping();
        if(count($mapping)){
            $returnValue = Array();
            $returnValue['identifier'] = $this->getIdentifier();
            $returnValue['defaultValue'] = $this->mappingDefaultValue;
            if($this->hasAttribute('areaMapping')){
                $returnValue = array_merge($returnValue, $this->getAttributeValue('areaMapping'));
            }
            $mappingValue = Array();

            // If a mapping has been defined
            if(!empty($mapping)){
                foreach($mapping as $mapKey => $mappedValue){
                    $mapEntryJSON = Array();
                    $mapEntryJSON['value'] = (float) $mappedValue;
                    $mapEntryJSON['key'] = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($mapKey, $this->getAttributeValue('baseType'));
                    array_push($mappingValue, (object) $mapEntryJSON);
                }

                $returnValue['value'] = $mappingValue;
            }

            $returnValue = (object) $returnValue;
        }

        return $returnValue;
    }
730367
public function decode($key, $default = null)
    {
        $input = $this->get($key, $default);
        if ($input AND is_string($input)) {
            $input = json_decode($input, true);
        }

        return (array)$input;
    }
1131799
private function getDefaultValue($key, $default = null)
    {
        $value = null === $default && \array_key_exists($key, $this->defaults)
            ? $this->defaults[$key]
            : $default;

        return $this->getByManager($key, $value, $default);
    }