Convert the current array to JSON.

@param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p>
@param int $depth   [optional] <p>Set the maximum depth. Must be greater than zero.</p>

@return string
161249
public function toJson(int $options = 0, int $depth = 512): string
    {
        /** @noinspection PhpComposerExtensionStubsInspection */
        $return = \json_encode($this->getArray(), $options, $depth);
        if ($return === false) {
            return '';
        }

        return $return;
    }
1216794
public function serialize(Options $options)
    {
        return [
            'id' => $options->getId(),
            'data' => $options->getOptions(),
            'user' => $this->userSerializer->serialize($options->getUser()),
        ];
    }
837972
public function encode($data, int $options = 0, int $depth = 512): string
    {
        // @7.3 use JSON_THROW_ON_ERROR
        $encoded = json_encode($data, $options, $depth);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new EncodeException(json_last_error_msg());
        }

        return $encoded;
    }
1074571
public function decode(string $data, bool $assoc = true, int $depth = 512, int $options = 0)
    {
        // @7.3 use JSON_THROW_ON_ERROR
        $decoded = json_decode($data, $assoc, $depth, $options);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new DecodeException(json_last_error_msg());
        }

        return $decoded;
    }
670360
public function toJSONI18N(Entity $entity, array $locales=[], $depth=0) {
		if(!$locales)
			$locales = $entity->getLocales();
		return json_encode($entity->toArrayI18N($locales, $depth));
	}
850463
public function apiSerialize($object, $options = [])
    {
        if (!empty($object)) {
            return $this->serializerProvider->serialize($object, $options);
        }

        return $object;
    }
36515
public function toJson($content, $options = [])
    {
        $options = $options + ['random' => false, 'repeated_view' => true];
        $options['repeater_id'] = $content;
        $repeaterRows = PageBlockRepeaterData::loadRepeaterData($content, $options['version'], $options['random']);
        $data = ['rows' => [], 'repeater_id' => $content];

        foreach ($repeaterRows as $rowId => $rowBlockData) {
            $data['rows'][$rowId] = [];

            foreach ($rowBlockData as $key => $rowContent) {
                $block = Block::preload($key);
                if ($block->exists) {
                    $data['rows'][$rowId] += json_decode($block->getTypeObject()->toJson($rowContent, $options), true);
                }
            }
        }

        return parent::toJson($data, $options);
    }
134521
public function export(&$value, int $depth = null): string
    {
        if (null === $depth) {
            $depth = $this->depth;
        }

        $final = (object) [];
        $stack = [[&$value, $final, 0, gettype($value)]];
        $results = [];
        $seenWrappers = new SplObjectStorage();
        $seenObjects = new SplObjectStorage();
        $seenArrays = [];
        $arrayResults = [];
        $arrayId = 0;

        while (!empty($stack)) {
            $entry = array_shift($stack);
            $value = &$entry[0];
            $result = $entry[1];
            $currentDepth = $entry[2];
            $type = $entry[3];
            $results[] = $result;

            switch ($type) {
                case 'NULL':
                    $result->type = 'null';

                    break;

                case 'boolean':
                    if ($value) {
                        $result->type = 'true';
                    } else {
                        $result->type = 'false';
                    }

                    break;

                case 'integer':
                    $result->type = strval($value);

                    break;

                case 'double':
                    $result->type = sprintf('%e', $value);

                    break;

                case 'resource':
                    $result->type = 'resource#' . intval($value);

                    break;

                case 'string':
                    $result->type = json_encode($value, $this->jsonFlags);

                    break;

                case 'array':
                    if (isset($value[self::ARRAY_ID_KEY])) {
                        $id = $value[self::ARRAY_ID_KEY];
                    } else {
                        $id = $value[self::ARRAY_ID_KEY] = $arrayId++;
                    }

                    $seenArrays[$id] = &$value;

                    if (isset($arrayResults[$id])) {
                        $result->type = '&' . $id . '[]';

                        break;
                    }

                    $result->type = '#' . $id;

                    if ($depth > -1 && $currentDepth >= $depth) {
                        $count = count($value) - 1;

                        if ($count) {
                            $result->type .= '[~' . $count . ']';
                        } else {
                            $result->type .= '[]';
                        }

                        break;
                    }

                    $arrayResults[$id] = $result;

                    $result->children = [];
                    $result->sequence = true;
                    $sequenceKey = 0;

                    foreach ($value as $key => &$childValue) {
                        if (self::ARRAY_ID_KEY === $key) {
                            continue;
                        }

                        if ($result->sequence) {
                            if ($key !== $sequenceKey++) {
                                $result->map = true;
                                $result->sequence = false;
                            }
                        }

                        $keyResult = (object) [];
                        $valueResult = (object) [];
                        $result->children[] = [$keyResult, $valueResult];

                        $stack[] = [
                            $key,
                            $keyResult,
                            $currentDepth + 1,
                            gettype($key),
                        ];
                        $stack[] = [
                            &$childValue,
                            $valueResult,
                            $currentDepth + 1,
                            gettype($childValue),
                        ];
                    }

                    break;

                case 'object':
                    $hash = spl_object_hash($value);

                    if (isset($this->objectIds[$hash])) {
                        $id = $this->objectIds[$hash];
                    } else {
                        $id = $this->objectIds[$hash] =
                            $this->objectSequencer->next();
                    }

                    if ($seenWrappers->contains($value)) {
                        $result->type = '&' . $id . '()';

                        break;
                    }

                    if ($seenObjects->contains($value)) {
                        $result->type = '&' . $id . '{}';

                        break;
                    }

                    if ($value instanceof Closure) {
                        $isWrapper = false;
                        $isClosure = true;
                        $isException = false;
                        $isHandle = false;
                        $isSpy = false;
                        $isStub = false;
                        $isGeneratorSpy = false;
                        $isIterableSpy = false;
                    } elseif ($value instanceof Throwable) {
                        $isWrapper = false;
                        $isClosure = false;
                        $isException = true;
                        $isHandle = false;
                        $isSpy = false;
                        $isStub = false;
                        $isGeneratorSpy = false;
                        $isIterableSpy = false;
                    } elseif ($value instanceof Generator) {
                        $isWrapper = isset($value->_phonySubject);
                        $isClosure = false;
                        $isException = false;
                        $isHandle = false;
                        $isSpy = false;
                        $isStub = false;
                        $isGeneratorSpy = $isWrapper;
                        $isIterableSpy = false;
                    } elseif ($value instanceof Handle) {
                        $isWrapper = true;
                        $isClosure = false;
                        $isException = false;
                        $isHandle = true;
                        $isSpy = false;
                        $isStub = false;
                        $isGeneratorSpy = false;
                        $isIterableSpy = false;

                        $isStaticHandle = $value instanceof StaticHandle;
                    } elseif ($value instanceof Stub) {
                        $isWrapper = true;
                        $isClosure = false;
                        $isException = false;
                        $isHandle = false;
                        $isSpy = false;
                        $isStub = true;
                        $isGeneratorSpy = false;
                        $isIterableSpy = false;

                        $isStubVerifier = $value instanceof StubVerifier;
                    } elseif ($value instanceof Spy) {
                        $isWrapper = true;
                        $isClosure = false;
                        $isException = false;
                        $isHandle = false;
                        $isSpy = true;
                        $isStub = false;
                        $isGeneratorSpy = false;
                        $isIterableSpy = false;

                        $isSpyVerifier = $value instanceof SpyVerifier;
                    } elseif ($value instanceof IterableSpy) {
                        $isWrapper = true;
                        $isClosure = false;
                        $isException = false;
                        $isHandle = false;
                        $isSpy = false;
                        $isStub = false;
                        $isGeneratorSpy = false;
                        $isIterableSpy = true;
                    } else {
                        $isWrapper = false;
                        $isClosure = false;
                        $isException = false;
                        $isHandle = false;
                        $isSpy = false;
                        $isStub = false;
                        $isGeneratorSpy = false;
                        $isIterableSpy = false;
                    }

                    $isMock = $value instanceof Mock;

                    if ($isClosure) {
                        $result->type = 'Closure';
                    } elseif ($isHandle) {
                        if ($isStaticHandle) {
                            $result->type = 'static-handle';
                        } else {
                            $result->type = 'handle';
                        }
                    } elseif ($isStub) {
                        $result->type = 'stub';
                    } elseif ($isSpy) {
                        $result->type = 'spy';
                    } elseif ($isGeneratorSpy) {
                        $result->type = 'generator-spy';
                    } elseif ($isIterableSpy) {
                        $result->type = 'iterable-spy';
                    } else {
                        $result->type = get_class($value);
                    }

                    $phpValues = (array) $value;

                    if ($isHandle) {
                        if ($isStaticHandle) {
                            $result->child = (object) [
                                'final' => $phpValues[
                                    "\0" . StaticHandle::class . "\0class"
                                ]->getName(),
                            ];
                        } else {
                            $result->child = (object) [];
                            $stack[] = [
                                $phpValues[
                                    "\0" . InstanceHandle::class . "\0mock"
                                ],
                                $result->child,
                                $currentDepth,
                                'object',
                            ];
                        }
                    } elseif ($isSpy) {
                        if ($isSpyVerifier) {
                            $phpValues = (array) $phpValues[
                                "\0" . SpyVerifier::class . "\0spy"
                            ];
                        }

                        if (!$phpValues["\0*\0isAnonymous"]) {
                            $result->child = (object) [
                                'final' => $this->exportCallable(
                                    $phpValues["\0*\0callback"]
                                ),
                            ];
                        }

                        $result->label = $phpValues["\0*\0label"];
                    } elseif ($isStub) {
                        if ($isStubVerifier) {
                            $phpValues = (array) $phpValues[
                                "\0" . StubVerifier::class . "\0stub"
                            ];
                        }

                        if (!$phpValues["\0*\0isAnonymous"]) {
                            $result->child = (object) [
                                'final' => $this->exportCallable(
                                    $phpValues["\0*\0callback"]
                                ),
                            ];
                        }

                        $result->label = $phpValues["\0*\0label"];
                    } elseif ($isGeneratorSpy) {
                        $result->child = (object) [];
                        $stack[] = [
                            $value->_phonySubject,
                            $result->child,
                            $currentDepth,
                            'object',
                        ];
                    } elseif ($isIterableSpy) {
                        $iterable = $value->iterable();
                        $result->child = (object) [];
                        $stack[] = [
                            $iterable,
                            $result->child,
                            $currentDepth,
                            gettype($iterable),
                        ];
                    }

                    if ($isWrapper) {
                        $result->wrapper = true;
                        $result->type .= '#' . $id;
                        $seenWrappers->offsetSet($value, true);
                    } else {
                        unset($phpValues["\0gcdata"]);

                        if ($isMock) {
                            $handleProperty =
                                "\0" . $result->type . "\0_handle";

                            if ($phpValues[$handleProperty]) {
                                $result->label =
                                    $phpValues[$handleProperty]->label();
                            }

                            unset($phpValues[$handleProperty]);
                        }

                        if ($isException) {
                            unset(
                                $phpValues["\0*\0file"],
                                $phpValues["\0*\0line"],
                                $phpValues["\0Exception\0trace"],
                                $phpValues["\0Exception\0string"],
                                $phpValues['xdebug_message']
                            );
                        } elseif ($isClosure) {
                            $reflector = new ReflectionFunction($value);
                            $result->label =
                                basename($reflector->getFilename()) . ':' .
                                $reflector->getStartLine();
                            $phpValues = [];
                        }

                        $properties = [];
                        $propertyCounts = [];

                        foreach (
                            $phpValues as $propertyName => $propertyValue
                        ) {
                            if (
                                preg_match(
                                    '/^\x00([^\x00]+)\x00([^\x00]+)$/',
                                    (string) $propertyName,
                                    $matches
                                )
                            ) {
                                if (
                                    '*' === $matches[1] ||
                                    $result->type === $matches[1]
                                ) {
                                    $propertyName = $realName = $matches[2];
                                } else {
                                    $propertyName = $matches[2];
                                    $realName =
                                        $matches[1] . '.' . $propertyName;
                                }

                                $properties[] = [
                                    $propertyName,
                                    $realName,
                                    $propertyValue,
                                ];
                            } else {
                                $properties[] = [
                                    $propertyName,
                                    $propertyName,
                                    $propertyValue,
                                ];
                            }

                            if (isset($propertyCounts[$propertyName])) {
                                $propertyCounts[$propertyName] += 1;
                            } else {
                                $propertyCounts[$propertyName] = 1;
                            }
                        }

                        $values = [];

                        foreach ($properties as $property) {
                            list($shortName, $realName, $propertyValue) =
                                $property;

                            if ($propertyCounts[$shortName] > 1) {
                                $values[$realName] = $propertyValue;
                            } else {
                                $values[$shortName] = $propertyValue;
                            }
                        }

                        if ($isException) {
                            if ('' === $values['message']) {
                                unset($values['message']);
                            }
                            if (0 === $values['code']) {
                                unset($values['code']);
                            }
                            if (!$values['previous']) {
                                unset($values['previous']);
                            }
                        }

                        if ('stdClass' === $result->type) {
                            $result->type = '';
                        }

                        $result->type .= '#' . $id;

                        if ($depth > -1 && $currentDepth >= $depth) {
                            if (empty($values)) {
                                $result->type .= '{}';
                            } else {
                                $result->type .= '{~' . count($values) . '}';
                            }

                            break;
                        }

                        $seenObjects->offsetSet($value, true);

                        $result->children = [];
                        $result->object = true;

                        foreach ($values as $key => &$childValue) {
                            $valueResult = (object) [];
                            $result->children[] = [$key, $valueResult];

                            $stack[] = [
                                &$childValue,
                                $valueResult,
                                $currentDepth + 1,
                                gettype($childValue),
                            ];
                        }
                    }

                    break;

                // @codeCoverageIgnoreStart
                default:
                    $result->type = '???';
                // @codeCoverageIgnoreEnd
            }
        }

        foreach (array_reverse($results) as $result) {
            $result->final = $result->type;

            if (isset($result->wrapper)) {
                if (isset($result->child)) {
                    $result->final .= '(' . $result->child->final . ')';
                }
            } elseif (isset($result->object)) {
                $result->final .= '{';
                $isFirst = true;

                foreach ($result->children as $pair) {
                    if (!$isFirst) {
                        $result->final .= ', ';
                    }

                    $result->final .= $pair[0] . ': ' . $pair[1]->final;
                    $isFirst = false;
                }

                $result->final .= '}';
            } elseif (isset($result->map)) {
                $result->final .= '[';
                $isFirst = true;

                foreach ($result->children as $pair) {
                    if (!$isFirst) {
                        $result->final .= ', ';
                    }

                    $result->final .=
                        $pair[0]->final . ': ' . $pair[1]->final;
                    $isFirst = false;
                }

                $result->final .= ']';
            } elseif (isset($result->sequence)) {
                $result->final .= '[';
                $isFirst = true;

                foreach ($result->children as $pair) {
                    if (!$isFirst) {
                        $result->final .= ', ';
                    }

                    $result->final .= $pair[1]->final;
                    $isFirst = false;
                }

                $result->final .= ']';
            }

            if (isset($result->label)) {
                $result->final .= '[' . $result->label . ']';
            }
        }

        foreach ($seenArrays as &$value) {
            unset($value[self::ARRAY_ID_KEY]);
        }

        return $final->final;
    }
42236
public function decodeJson($jsonValue, $assoc = false, $depth = null, $options = null)
    {
        return $this->utilEncodingService->decodeJson($jsonValue, $assoc, $depth, $options);
    }
908275
public function outputJson($data, $options = array())
    {
        $this->addHeader('Content-Type', 'application/json')
            ->addOptionalHeaders($options)
            ->sendHeaders();

        echo gplcart_json_encode($data);
        exit;
    }
920112
public function serialize($object, $options = [])
    {
        if (!$object) {
            return $object;
        }

        $data = $this->get($object)->serialize($object, $options);

        //if a serializer wants to return a stdClass, we want an array
        if (is_object($data)) {
            $data = json_decode(json_encode($data), true);
        }

        return $data;
    }
82388
public static function encode($value, $options = null)
    {
        if ($options === null) {
            $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
        }

        $json = json_encode($value, $options);

        static::handleJsonError(json_last_error());

        return $json;
    }
1362114
public function encode(array $options = [])
    {
        $options = array_replace(
            [
                'encodingOptions'       => $this->getOption('encodingOptions')
            ],
            $options
        );

        $json = json_encode($this->getContents(), $options['encodingOptions']);

        if ($json === false) {
            switch (json_last_error()) {
                case JSON_ERROR_DEPTH:
                    $msg = 'The maximum stack depth has been exceeded.';

                    break;
                case JSON_ERROR_STATE_MISMATCH:
                    $msg = 'Occurs with underflow or with the modes mismatch.';

                    break;
                case JSON_ERROR_CTRL_CHAR:
                    $msg = 'Control character error, possibly incorrectly encoded.';

                    break;
                case JSON_ERROR_UTF8:
                    $msg = 'alformed UTF-8 characters, possibly incorrectly encoded.';

                    break;
                default:
                    $msg = 'Unknown error';
            }

            throw EncodeException::create($this->getPath(), $msg);
        }

        return $json;
    }
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));
    }
571305
public function toJson($options = 0, $structure, $assoc = true)
    {
        return json_encode(
            $this->toOutput($structure, $assoc),
            $options
        );
    }
242961
public function serialize($value, array $options=[])
    {

        $serialized = json_encode(
            $value,
            $this->bitmask($options),
            $this->getDepth($options)
        );

        return $serialized;

    }
44241
public function serialize(CompetencyAbility $competencyAbility, array $options = [])
    {
        $serialized = [
            'id' => $competencyAbility->getUuid(),
            'level' => $this->levelSerializer->serialize($competencyAbility->getLevel(), [Options::SERIALIZE_MINIMAL]),
            'competency' => [
                'id' => $competencyAbility->getCompetency()->getUuid(),
            ],
            'ability' => $this->abilitySerializer->serialize($competencyAbility->getAbility(), [Options::SERIALIZE_MINIMAL]),
        ];

        return $serialized;
    }