Converts an object into a JSON formatted string.

@param   object  $object   Data source object.
@param   array   $options  Options used by the formatter.
@return  string  JSON formatted string.
500339
public function objectToString($object, $options = array())
	{
		if (is_string($object))
		{
			return $object;
		}

		if (isset($options['pretty_print']) && $options['pretty_print'])
		{
			return json_encode($object, JSON_PRETTY_PRINT);
		}

		return json_encode($object);
	}
198578
public function copy($object, array $options = [])
    {
        $this->checkPermission('COPY', $object, [], true);
        $class = get_class($object);
        $new = new $class();

        $this->serializer->deserialize(
          $this->serializer->serialize($object),
          $new
        );

        $this->om->persist($new);

        //first event is the pre one
        if ($this->dispatch('copy', 'pre', [$object, $options, $new])) {
            //second event is the post one
            //we could use only one event afaik
            $this->dispatch('copy', 'post', [$object, $options, $new]);
        }

        $this->om->flush();

        return $new;
    }
417058
protected function getObjectString($object)/*# : string */
    {
        // exception found
        if ($object instanceof \Exception) {
            return 'EXCEPTION: ' . $object->getMessage();

        // toString() found
        } elseif (method_exists($object, '__toString')) {
            return (string) $object;

        // other type object
        } else {
            return 'OBJECT: ' . get_class($object);
        }
    }
1257182
public function json(array $data = array(), $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
    {

        if (!headers_sent())
        {
            header('Cache-Control: no-cache, must-revalidate');
            header('Expires: Tue, 19 May 1981 18:00:00 GMT');
            header('Content-type: application/json; charset=utf-8');
        }

        /**
         * @var \Deimos\Helper\Helpers\Json $json
         */
        $json = clone $this->helper->json();
        $json->setOption((array)$options);

        return $json->encode($data);

    }
1067208
public static String toJSONString(Object object) {
        if (object == null) {
            return null;
        }
        return JSONObject.toJSONString(object);
    }
838177
public function deserialize($data, $object, $options = [])
    {
        // search for the correct serializer
        if ($meta = $this->om->getClassMetaData(get_class($object))) {
            $class = $meta->name;
        }

        $serializer = $this->get($class);

        if (method_exists($serializer, 'deserialize')) {
            $serializer->deserialize($data, $object, $options);
        }

        return $object;
    }
1143832
public function objectToString($object, $options = array())
	{
		if (is_string($object))
		{
			return $object;
		}

		return SymfonyYaml::dump((array) $this->asArray($object), 2);
	}
82213
private function serializeBodyObject($object): string
    {
        try {
            return $this->serializer->serialize($object, 'atol_client', $this->getSerializeBodyObjectContext());
        } catch (\RuntimeException $exception) {
            throw ParseException::becauseOfRuntimeException($exception, ParseException::REQUEST);
        }
    }
649377
public function save($object, array $options = []) {
		$returnobject = [];
		$returnobject['result'] = false;
		$returnobject['msg'] = '';

		if (empty($object)) {
			return $returnobject;
		}

		//Create filename based on timestamp and random number (to prevent collisions)
		$object['filename'] = $this->generateFilename($object);

		if ($this->saveFile($object, $options['location'])) {
			$msg = __d('feedback', 'Thank you. Your feedback was saved.');

			if (!empty($options['returnlink'])) {
				$msg .= ' ';
				$msg .= __d('feedback', 'View your feedback on: ');

				$url = Router::url(['plugin' => 'Feedback', 'controller' => 'Feedback', 'action' => 'index'], true);

				$msg .= '<a target="_blank" href="' . $url . '">' . $url . '</a>';
			}

			$returnobject['result'] = true;
			$returnobject['msg'] = $msg;
		}

		return $returnobject;
	}
612549
public function toJSON($options = 0)
    {
        // Because of PHP Version 5.3, we cannot use JSON_UNESCAPED_SLASHES option
        // Instead we would use the str_replace command for now.
        if (version_compare(phpversion(), '5.4.0', '>=') === true) {
            return json_encode($this->toArray(), $options | 64);
        }
        return str_replace('\\/', '/', json_encode($this->toArray(), $options));
    }
1147984
public static function toArray($object)
	{
		if(is_array($object))
			return $object;
		elseif(!is_object($object))
			return (array) $object;
		elseif ($object instanceof IlluminateCollection)
			return $object->all();
		elseif ($object instanceof IlluminateArrayable)
			return $object->toArray();
		elseif(method_exists($object, '__toString'))
			return [$object];
		elseif ($object instanceof IlluminateJsonable)
			return (array) json_decode($object->toJson(), true);
		elseif ($object instanceof JsonSerializable)
			return (array) $object->jsonSerialize();
		elseif ($object instanceof Traversable)
			return iterator_to_array($object);
		else
			return (array) $object;
	}
152559
public function toJson($key = null, $options = 0)
    {
        if (is_string($key)) {
            return json_encode($this->get($key), $options);
        }
        $options = $key === null ? 0 : $key;
        return json_encode($this->elements, $options);
    }
1019697
public function objectToString($obj)
    {
        switch (gettype($obj)) {
            case 'boolean':
                return var_export($obj, true);

            case 'NULL':
                return 'null';

            case 'string':
                return '"' . $obj . '"';
        }

        return rtrim(print_r($obj, true));
    }
1073648
public function strip_empty_keys($object){

		$json = json_encode($object);
		$json = preg_replace('/,\s*"[^"]+":null|"[^"]+":null,?/', '', $json);
		$object = json_decode($json);

		return $object;
    }
249210
public static function to_array($object) {
        if (is_array($object)) return $object;
        if (!is_object($object) && !is_array($object)) return $object;
        if (is_object($object)) $object = get_object_vars($object);

        return array_map([
            __CLASS__,
            'to_array'
        ], $object);
    }
1222255
public function toJson($options = 0)
    {
        if ($this->object instanceof Jsonable) {
            return $this->object->toJson();
        }

        return json_encode($this->object);
    }
47566
public static function objectToString($object): string {
        //TODO do type hinting when possible
        if (!\is_object($object)) {
            throw new InvalidKeyTypeException("key has to be an object, " . \gettype($object) . "given");
        }
        return \serialize($object);
    }