@param mixed $json

@throws ValidationException
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);
        }
    }
588775
protected function createJsonDefinition($json)
    {
        $errors = $this->validator->validateJsonDefinition($json);
        if (!empty($errors)) {
            throw new ValidationException($errors);
        }

        $definition = $this->serializer->deserialize(
            $json,
            'Graviton\\GeneratorBundle\\Definition\\Schema\\Definition',
            'json'
        );

        return new JsonDefinition($definition);
    }
628239
protected function parse($object)
    {
        if (! is_object($object)) {
            throw new ValidationException('ErrorSource has to be an object, "' . gettype($object) . '" given.');
        }

        if (property_exists($object, 'pointer')) {
            if (! is_string($object->pointer)) {
                throw new ValidationException('property "pointer" has to be a string, "' . gettype($object->pointer) . '" given.');
            }

            $this->set('pointer', strval($object->pointer));
        }

        if (property_exists($object, 'parameter')) {
            if (! is_string($object->parameter)) {
                throw new ValidationException('property "parameter" has to be a string, "' . gettype($object->parameter) . '" given.');
            }

            $this->set('parameter', strval($object->parameter));
        }
    }
743808
private function setJsonData(?string $json): self
    {
        $this->updatePropertyValue(
            JsonDataFieldInterface::PROP_JSON_DATA,
            $json
        );

        return $this;
    }
995552
protected function validate(stdClass $data): void
    {
        $config = $this->getConfig();
        $schema = $this->readSchema();

        // No need to validate empty data (empty() does not work on objects)
        $dataArray = Convert::objectToArray($data);
        if (empty($dataArray)) {
            if ($config['allowEmptyData'] === false) {
                throw new JsonValidationException('Empty data is not allowed.');
            }
            $this->warnings[] = "Skipping validation of empty data";

            return;
        }

        // No need to validate with empty schema (empty() does not work on objects)
        $schemaArray = Convert::objectToArray($schema);
        if (empty($schemaArray)) {
            if ($config['allowEmptySchema'] === false) {
                throw new JsonValidationException('Empty schema is not allowed.');
            }
            $this->warnings[] = "Skipping validation with empty schema";

            return;
        }

        $this->runValidator($data, $schema);
    }
585808
protected function parse($object)
    {
        if (! is_object($object)) {
            throw new ValidationException('Relationship has to be an object, "' . gettype($object) . '" given.');
        }

        if (! property_exists($object, 'links') and ! property_exists($object, 'data') and ! property_exists($object, 'meta')) {
            throw new ValidationException('A Relationship object MUST contain at least one of the following properties: links, data, meta');
        }

        if (property_exists($object, 'data')) {
            if ($object->data === null) {
                $this->set('data', $object->data);
            } elseif (is_array($object->data)) {
                $this->set('data', $this->create('ResourceIdentifierCollection', $object->data));
            } else {
                $this->set('data', $this->create('ResourceIdentifier', $object->data));
            }
        }

        if (property_exists($object, 'meta')) {
            $this->set('meta', $this->create('Meta', $object->meta));
        }

        // Parse 'links' after 'data'
        if (property_exists($object, 'links')) {
            $this->set('links', $this->create('RelationshipLink', $object->links));
        }
    }
458510
public static function validateConditionsConfig(array $json) : void
    {
        foreach ($json as $condition) {
            if (!self::keysExist(['exec'], $condition) || empty($condition['exec'])) {
                throw new \RuntimeException('Config error: \'exec\' is required for conditions');
            }
            if (!empty($condition['args']) && !is_array($condition['args'])) {
                throw new \RuntimeException('Config error: invalid \'args\' configuration');
            }
        }
    }
288522
private function simple_json_parser($json){
        $json = str_replace("{","",str_replace("}","", $json));
        $jsonValue = explode(",", $json);
        $arr = array();
        foreach($jsonValue as $v){
            $jValue = explode(":", $v);
            $arr[str_replace('"',"", $jValue[0])] = (str_replace('"', "", $jValue[1]));
        }
        return $arr;
    }
136328
protected function parse($object)
    {
        if (! is_object($object)) {
            throw new ValidationException('Resource has to be an object, "' . gettype($object) . '" given.');
        }

        if (! property_exists($object, 'type')) {
            throw new ValidationException('A resource object MUST contain a type');
        }

        if (is_object($object->type) or is_array($object->type)) {
            throw new ValidationException('Resource type cannot be an array or object');
        }

        $this->set('type', strval($object->type));

        if (
            $this->getManager()->getParam('optional_item_id', false) === false
            or ! $this->getParent()->has('data') // If parent has no `data` than parent is a ResourceCollection
        ) {
            if (! property_exists($object, 'id')) {
                throw new ValidationException('A resource object MUST contain an id');
            }

            if (is_object($object->id) or is_array($object->id)) {
                throw new ValidationException('Resource id cannot be an array or object');
            }

            $this->set('id', strval($object->id));
        }

        if (property_exists($object, 'meta')) {
            $this->set('meta', $this->create('Meta', $object->meta));
        }

        if (property_exists($object, 'attributes')) {
            $this->set('attributes', $this->create('Attributes', $object->attributes));
        }

        if (property_exists($object, 'relationships')) {
            $this->set('relationships', $this->create('RelationshipCollection', $object->relationships));
        }

        if (property_exists($object, 'links')) {
            $this->set('links', $this->create('ResourceItemLink', $object->links));
        }
    }
640044
private function processJson($json)
    {
        $twee_array = json_decode($json, true);

        if (!isset($twee_array['data']) or empty($twee_array['data'])) {
            throw new RuntimeException("The provided JSON did not decode or is empty.");
        }

        foreach ($twee_array['data'] as $entity) {
            $type = $this->getTypeFromTags($entity['tags']);
            if (empty($type)) {
                $type = $this->getTypeFromTitle($entity['title']);
            }
            switch ($type) {
                case 'passage':
                    $passage = new TweePassage($entity);
                    $this->passages[$passage->title] = $passage;
                    // Set the start passage
                    if (in_array('start', $passage->tags)) {
                        $this->current_passage = $passage->title;
                        $this->history[] = $this->current_passage;
                        $this->storyline[] = $this->current_passage;
                    }
                    break;
                case 'title':
                    $this->title = $entity['text'];
                    break;
                case 'script':
                    $this->scripts[] = $entity['text'];
                    break;
                case 'stylesheet':
                    $this->stylesheets[] = $entity['text'];
                    break;
                default:
                    throw new \RuntimeException("Unknown entity type!");
            }
        }
        return true;
    }
230037
public function fromJson($json) {
    Helpers::checkType('json', 'string', $json);
    $decoded_value = json_decode($json);
    if ($decoded_value === null && ($json !== 'null' || $json !== '')) {
      throw new \Exception('Invalid JSON.');
    }
    return $this->setValue($decoded_value);
  }
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'];
        }
    }
277773
protected function onData($json)
    {
        // Decode the JSON
        $interaction = json_decode(trim($json), true);

        // If the interaction is valid, pass it to the event handler
        if ($interaction) {
            if (isset($interaction['status'])) {
                switch ($interaction['status']) {
                    case 'error':
                    case 'failure':
                        $this->onError($interaction['message']);
                        // Stop the consumer when an error is received
                        $this->stop();
                        break;
                    case 'warning':
                        $this->onWarning($interaction['message']);
                        break;
                    default:
                        $type = $interaction['status'];
                        unset($interaction['status']);
                        $this->onStatus($type, $interaction);
                        break;
                }
            } else {
                // Extract the hash and the data if present
                $hash = false;
                if (isset($interaction['hash'])) {
                    $hash = $interaction['hash'];
                    $interaction = $interaction['data'];
                }
                // Ignore ticks and handle delete requests
                if (! empty($interaction['deleted'])) {
                    $this->onDeleted($interaction, $hash);
                } elseif (! empty($interaction['interaction'])) {
                    $this->onInteraction($interaction, $hash);
                }
            }
        }
    }
354148
public function setAuthConfig($json)
    {
        $data = json_decode($json);
        $this->setClientId($data->client_id);
        $this->setClientSecret($data->client_secret);
    }
636191
private function validateSchema($json)
    {
        $jsonData = json_decode($json);
        $schemaData = json_decode(file_get_contents($this->configurationSchema));

        $validator = new Validator();
        $validator->check($jsonData, $schemaData);
        if ($validator->isValid() === false) {
            $errors = array();
            foreach ($validator->getErrors() as $error) {
                $errorMessage = $error['message'];
                if (isset($error['property'])) {
                    $errorMessage = $error['property'].' : '.$errorMessage;
                }
                $errors[] = $errorMessage;
            }

            throw new JSONValidationException(sprintf('The configuration file "%s" does not match the expected JSON schema.', $this->configurationFile), $errors);
        }

        return true;
    }
278183
public static function validateResponse($json)
    {

        $result = json_decode($json);

        // switch and check possible JSON errors
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                return $result;
                break;
            case JSON_ERROR_DEPTH:
                $error = 'The maximum stack depth has been exceeded.';
                break;
            case JSON_ERROR_STATE_MISMATCH:
                $error = 'Invalid or malformed JSON.';
                break;
            case JSON_ERROR_CTRL_CHAR:
                $error = 'Control character error, possibly incorrectly encoded.';
                break;
            case JSON_ERROR_SYNTAX:
                $error = 'Syntax error, malformed JSON.';
                break;
            // PHP >= 5.3.3
            case JSON_ERROR_UTF8:
                $error = 'Malformed UTF-8 characters, possibly incorrectly encoded.';
                break;
            // PHP >= 5.5.0
            case JSON_ERROR_RECURSION:
                $error = 'One or more recursive references in the value to be encoded.';
                break;
            // PHP >= 5.5.0
            case JSON_ERROR_INF_OR_NAN:
                $error = 'One or more NAN or INF values in the value to be encoded.';
                break;
            case JSON_ERROR_UNSUPPORTED_TYPE:
                $error = 'A value of a type that cannot be encoded was given.';
                break;
            default:
                $error = 'Unknown JSON error occured.';
                break;
        }

        throw new InvalidJsonException($error);
    }
71518
protected function parse($object)
    {
        if (! is_object($object)) {
            throw new ValidationException('Link has to be an object or string, "' . gettype($object) . '" given.');
        }

        if (! array_key_exists('href', $object)) {
            throw new ValidationException('Link must have a "href" attribute.');
        }

        foreach (get_object_vars($object) as $name => $value) {
            $this->setAsLink($name, $value);
        }
    }