Embed data of Open Badges Specification Version 2.0 to json.

@param array $json for assertion, badges, issuer.
@param string $type Content type.
423371
protected function embed_data_badge_version2 (&$json, $type = OPEN_BADGES_V2_TYPE_ASSERTION) {
        // Specification Version 2.0.
        if ($this->_obversion == OPEN_BADGES_V2) {
            $badge = new badge($this->_data->id);
            if (empty($this->_data->courseid)) {
                $context = context_system::instance();
            } else {
                $context = context_course::instance($this->_data->courseid);
            }

            $hash = $this->_data->uniquehash;
            $assertionsurl = new moodle_url('/badges/assertion.php', array('b' => $hash, 'obversion' => $this->_obversion));
            $classurl = new moodle_url(
                '/badges/assertion.php',
                array('b' => $hash, 'action' => 1, 'obversion' => $this->_obversion)
            );
            $issuerurl = new moodle_url('/badges/assertion.php', array('b' => $this->_data->uniquehash, 'action' => 0,
                'obversion' => $this->_obversion));
            // For assertion.
            if ($type == OPEN_BADGES_V2_TYPE_ASSERTION) {
                $json['@context'] = OPEN_BADGES_V2_CONTEXT;
                $json['type'] = OPEN_BADGES_V2_TYPE_ASSERTION;
                $json['id'] = $assertionsurl->out(false);
                $json['badge'] = $this->get_badge_class();
                $json['issuedOn'] = date('c', $this->_data->dateissued);
                if (!empty($this->_data->dateexpire)) {
                    $json['expires'] = date('c', $this->_data->dateexpire);
                }
                unset($json['uid']);
            }

            // For Badge.
            if ($type == OPEN_BADGES_V2_TYPE_BADGE) {
                $json['@context'] = OPEN_BADGES_V2_CONTEXT;
                $json['id'] = $classurl->out(false);
                $json['type'] = OPEN_BADGES_V2_TYPE_BADGE;
                $json['version'] = $this->_data->version;
                $json['criteria'] = $this->get_criteria_badge_class();
                $json['issuer'] = $this->get_issuer();
                $json['@language'] = $this->_data->language;
                if (!empty($relatedbadges = $this->get_related_badges($badge))) {
                    $json['related'] = $relatedbadges;
                }
                if ($endorsement = $this->get_endorsement()) {
                    $endorsementurl = new moodle_url('/badges/endorsement_json.php', array('id' => $this->_data->id));
                    $json['endorsement'] = $endorsementurl->out(false);
                }
                if ($alignments = $this->get_alignments()) {
                    $json['alignment'] = $alignments;
                }
                if ($this->_data->imageauthorname ||
                        $this->_data->imageauthoremail ||
                        $this->_data->imageauthorurl ||
                        $this->_data->imagecaption) {
                    $urlimage = moodle_url::make_pluginfile_url($context->id,
                        'badges', 'badgeimage', $this->_data->id, '/', 'f1')->out(false);
                    $json['image'] = array();
                    $json['image']['id'] = $urlimage;
                    if ($this->_data->imageauthorname || $this->_data->imageauthoremail || $this->_data->imageauthorurl) {
                        $authorimage = new moodle_url('/badges/image_author_json.php', array('id' => $this->_data->id));
                        $json['image']['author'] = $authorimage->out(false);
                    }
                    if ($this->_data->imagecaption) {
                        $json['image']['caption'] = $this->_data->imagecaption;
                    }
                }
            }

            // For issuer.
            if ($type == OPEN_BADGES_V2_TYPE_ISSUER) {
                $json['@context'] = OPEN_BADGES_V2_CONTEXT;
                $json['id'] = $issuerurl->out(false);
                $json['type'] = OPEN_BADGES_V2_TYPE_ISSUER;
            }
        }
    }
639515
public static function create(array $json)
    {
        $registerDeviceResponse = new RegisterDeviceResponse();
        $registerDeviceResponse->setStatusCode($json['status_code']);
        $registerDeviceResponse->setStatusMessage($json['status_message']);

        return $registerDeviceResponse;
    }
373423
private function depthHandler(array $json)
    {
        $symbol = $json['s'];
        if ($json['u'] <= $this->info[$symbol]['firstUpdate']) {
            return;
        }

        foreach ($json['b'] as $bid) {
            $this->depthCache[$symbol]['bids'][$bid[0]] = $bid[1];
            if ($bid[1] == "0.00000000") {
                unset($this->depthCache[$symbol]['bids'][$bid[0]]);
            }

        }
        foreach ($json['a'] as $ask) {
            $this->depthCache[$symbol]['asks'][$ask[0]] = $ask[1];
            if ($ask[1] == "0.00000000") {
                unset($this->depthCache[$symbol]['asks'][$ask[0]]);
            }

        }
    }
1242377
public function setJsonBody($data)
    {
        $body = json_encode($data, JSON_UNESCAPED_UNICODE);
        $this->setHeader('content-type', 'application/json');
        $this->setBody($body);
    }
932392
public function parseJson($json)
    {
        $this->id = $json['id'];
        $this->name = $json['name'];
        $this->links = $json['links'];

        if (isset($json['xmpp_jid'])) {
            $this->xmppJid = $json['xmpp_jid'];
            //Statistics need to be implemented
            $this->created = new \DateTime($json['created']);
            $this->archived = $json['is_archived'];
            $this->privacy = $json['privacy'];
            $this->guestAccessible = $json['is_guest_accessible'];
            $this->topic = $json['topic'];
            $this->participants = array();
            foreach ($json['participants'] as $participant) {
                $this->participants[] = new User($participant);
            }
            $this->owner = new User($json['owner']);
            $this->guestAccessUrl = $json['guest_access_url'];
        }
    }
858544
public static function isJSON($json)
    {
        if ($json === '[]' || $json === '{}') {
            return true;
        } else if (is_array($json)) {
            return false;
        }

        return static::decode($json) != null;
    }
698005
public static function ThrowIfJsonDefNotValid(string $type, array $array) : array
    {
        $jsonProps = $type::DaftObjectJsonPropertyNames();
        $array = JsonTypeUtilities::FilterThrowIfJsonDefNotValid($type, $jsonProps, $array);
        $jsonDef = $type::DaftObjectJsonProperties();

        $keys = array_keys($array);

        /**
        * @var array<int|string, scalar|(scalar|array|object|null)[]|object|null>
        */
        $out = array_combine($keys, array_map(
            JsonTypeUtilities::MakeMapperThrowIfJsonDefNotValid($type, $jsonDef, $array),
            $keys
        ));

        return $out;
    }
22016
protected function configure(Config $config, array $json) : void
    {
        Util::validateJsonConfiguration($json);

        foreach (HookUtil::getValidHooks() as $hook => $class) {
            if (isset($json[$hook])) {
                $this->configureHook($config->getHookConfig($hook), $json[$hook]);
            }
        }
    }
438645
private function guardValidnessWithJSONSchema($json)
    {
        // @todo JSON-SCHEMA inside swagger.json should be reused here
        $schema = json_decode('{
            "type": "object",
            "properties": {
                "description": {
                    "type": "string"
                }
            },
            "required": [
                "description"
            ],
            "additionalProperties": false
        }');

        $validator = new Validator();
        $validator->check($json, $schema);

        if (!$validator->isValid()) {
            $errors = $validator->getErrors();

            $errorMessages = $this->getErrorMessages($errors);

            throw new ValidationException($errorMessages);
        }
    }
425961
public function generateTsConfig($json)
    {
        // generate page TSconfig
        $content = "";
        $iconRegistry = GeneralUtility::makeInstance("TYPO3\CMS\Core\Imaging\IconRegistry");

        // make content-Elements
        if ($json["tt_content"]["elements"]) {
            foreach ($json["tt_content"]["elements"] as $element) {
                // Register icons for contentelements
                $iconIdentifier = 'mask-ce-' . $element["key"];
                $iconRegistry->registerIcon(
                    $iconIdentifier, "MASK\Mask\Imaging\IconProvider\ContentElementIconProvider", array(
                        'contentElementKey' => $element["key"]
                    )
                );

                if (!$element["hidden"]) {

                    // add the content element wizard for each content element
                    $wizard = [
                        'header' => 'LLL:EXT:mask/Resources/Private/Language/locallang_mask.xlf:new_content_element_tab',
                        'elements.mask_' . $element["key"] => [
                            'iconIdentifier' => $iconIdentifier,
                            'title' => $element["label"],
                            'description' => $element["description"],
                            'tt_content_defValues' => [
                                'CType' => 'mask_' . $element["key"]
                            ]
                        ],

                    ];
                    $content .= "mod.wizards.newContentElement.wizardItems.mask {\n";
                    $content .= $this->convertArrayToTypoScript($wizard, '', 1);
                    $content .= "\tshow := addToList(mask_" . $element["key"] . ");\n";
                    $content .= "}\n";

                    // and switch the labels depending on which content element is selected
                    $content .= "\n[userFunc = user_mask_contentType(CType|mask_" . $element["key"] . ")]\n";
                    if ($element["columns"]) {
                        foreach ($element["columns"] as $index => $column) {
                            $content .= " TCEFORM.tt_content." . $column . ".label = " . $element["labels"][$index] . "\n";
                        }
                    }
                    $content .= "[end]\n\n";
                }
            }
        }
        return $content;
    }
247219
public function setInlineTca($json)
    {
        // Generate TCA for IRRE Fields and Tables
        $notIrreTables = array("pages", "tt_content", "sys_file_reference");
        if ($json) {
            foreach ($json as $table => $subJson) {
                $fieldTCA = array();
                if (array_search($table, $notIrreTables) === false) {
                    // Generate Table TCA
                    $this->generateTableTca($table, $subJson["tca"]);
                    // Generate Field TCA
                    $fieldTCA = $this->generateFieldsTca($subJson["tca"]);
                    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns($table, $fieldTCA);

                    // set label for inline
                    if (!empty($json["tt_content"]["tca"][$table]["inlineLabel"])) {
                        $fields = array_keys($subJson["tca"]);
                        if (array_search($json["tt_content"]["tca"][$table]["inlineLabel"], $fields) !== false) {
                            $GLOBALS["TCA"][$table]["ctrl"]['label'] = $json["tt_content"]["tca"][$table]["inlineLabel"];
                        }
                    }
                    // set icon for inline
                    if (!empty($json["tt_content"]["tca"][$table]["inlineIcon"])) {
                        $GLOBALS["TCA"][$table]["ctrl"]['iconfile'] = $json["tt_content"]["tca"][$table]["inlineIcon"];
                    } else {
                        $GLOBALS["TCA"][$table]["ctrl"]['iconfile'] = "EXT:mask/Resources/Public/Icons/Extension.svg";
                    }

                    // hide table in list view
                    $GLOBALS["TCA"][$table]['ctrl']['hideTable'] = true;
                }
            }
        }
    }
680103
private function createTypedObject(stdClass $json)
    {
        $url = new Url($json->same_as);

        foreach ($this->urlValidators as $urlValidator) {
            $urlValidator->validateUrl($url);
        }

        return new CreateOfferVariation(
            $url,
            new OwnerId($json->owner),
            new Purpose($json->purpose),
            new Description($json->description)
        );
    }
570121
public function setJSON($json)
    {
        global $CFG;
        $PDOX = $this->launch->pdox;

        $stmt = $PDOX->queryDie(
            "UPDATE {$CFG->dbprefix}lti_result SET json = :json, updated_at = NOW()
                WHERE result_id = :RID",
            array(
                ':json' => $json,
                ':RID' => $this->id)
        );
    }
409179
protected function parseJson($type, \SimpleXMLElement $json)
    {
        if (!isset($json->$type)) {
            return false;
        }
        foreach ($json->$type as $url) {
            $this->addArray($type, (array)$url);
        }
        return true;
    }
469299
protected function createCurrencyFromJson($json) {
    $currency_data = json_decode($json);

    $currency = new Currency();
    $currency->setCurrencyCode($currency_data->ISO4217Code);
    if (isset($currency_data->ISO4217Number)) {
      $currency->setCurrencyNumber($currency_data->ISO4217Number);
    }
    if (isset($currency_data->alternativeSigns)) {
      $currency->setAlternativeSigns($currency_data->alternativeSigns);
    }
    $currency->setLabel($currency_data->title);
    if (isset($currency_data->roundingStep)) {
      $currency->setRoundingStep($currency_data->roundingStep);
    }
    if (isset($currency_data->sign)) {
      $currency->setSign($currency_data->sign);
    }
    if (isset($currency_data->subunits)) {
      $currency->setSubunits($currency_data->subunits);
    }

    $usages_data = $currency_data->usage;
    $usages = [];
    foreach ($currency_data as $property => $value) {
      $this->$property = $value;
    }
    foreach ($usages_data as $usage_data) {
      $usage = new Usage();
      if (isset($usage_data->ISO8601From)) {
        $usage->setStart($usage_data->ISO8601From);
      }
      if (isset($usage_data->ISO8601To)) {
        $usage->setEnd($usage_data->ISO8601To);
      }
      if (isset($usage_data->ISO3166Code)) {
        $usage->setCountryCode($usage_data->ISO3166Code);
      }
      $usages[] = $usage;
    }
    $currency->setUsages($usages);

    return $currency;
  }
255712
public static function encode($data, String $type = 'unescapedUnicode') : String
    {
        return json_encode($data, Helper::toConstant($type, 'JSON_'));
    }
809083
public function write($text, $type = 'stdout')
    {
        if (in_array($type, ['stdout', 'stderr']) && ! empty($text)) {
            $f = fopen('php://' . $type, 'w');

            if (is_array($text)) {
                $text = json_encode($text);
            }

            fwrite($f, $text);
            fclose($f);
        }
    }