Build the response from the expected JSON returned by the service.

@param string $json
@return \LosReCaptcha\Service\Response
186328
public static function fromJson($json)
    {
        $responseData = json_decode($json, true);

        if (! $responseData) {
            return new Response(false, ['invalid-json']);
        }

        if (isset($responseData['success']) && $responseData['success'] == true) {
            return new Response(true);
        }

        if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
            return new Response(false, $responseData['error-codes']);
        }

        return new Response(false);
    }
758224
protected function fetchJsonError($json) {
		if (isset($json->error)) {
			return array(
				'code' => $json->error_code,
				'message' => $json->error_description,
			);
		}
		else {
			return null;
		}
	}
594319
public static function groupsPage($json)
    {
        $fields = Deserialize::_fromJson($json);

        $result = new Api\Page();
        $result->setPage($fields->page);
        $result->setSize($fields->page_size);
        $result->setTotalSize($fields->count);
        $result->setContent(
            array_map(
                function ($s) use ($json) {
                    return Deserialize::_groupResponseFromFields($json, $s);
                },
                $fields->groups
            )
        );

        return $result;
    }
368497
public static function createFromJSON($json)
    {
        $object = json_decode($json);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(
                'JSON parse had errors - ' . json_last_error_msg()
            );
        }

        return static::createFromObject($object);
    }
174214
public function transformJsonResponse($json)
    {
        // In a REST-API call, the first five chars are )]}'\n
        // to decode it, we have to strip it
        // See https://review.typo3.org/Documentation/rest-api.html#output
        if (substr($json, 0, 4) === ')]}\'') {
            $json = substr($json, 5);
        }

        return json_decode($json, true);
    }
232127
public function fromJson(string $json): array
    {
        if (!$this->isEmptyValue($json)) {

            if ($decode = json_decode(trim($json), true) and json_last_error() == JSON_ERROR_NONE)
                $this->result = $decode;
            else
                $this->setError(json_last_error(), json_last_error_msg());
        }

        return $this->result;
    }
483684
private function captchaResponse($response)
    {
        $errors = ['g-recaptcha-response' => ['Oops, something went wrong']];
        foreach ($response->getErrorCodes() as $k => $code) {
            if ($code == 'missing-input-response') {
                $code = 'Please confirm you are not a robot.';
            }
            $errors['g-recaptcha-response'][$k] = $code;
        }

        return new JsonResponse($errors, 422);
    }
597302
protected function errorResponse($json)
    {
        $error = new Error('Bad Request', json_decode($json));

        return $this->createResponse(new BadRequest(new ErrorBag([$error])));
    }
1201243
static function json( $data, $code = 200 ) {
        return (new Response())
            ->setCode($code)
            ->setContent(json_encode($data))
            ->setContentType('application/json');
    }
1364809
public static function fromJson($json)
    {
        if (!is_object($json)) {
            $json = json_decode($json);
        }
        $properties = ['package', 'description', 'url', 'sha1', 'depth'];
        $patch = new static();

        foreach ($properties as $property) {
            if (isset($json->{$property})) {
                $patch->{$property} = $json->{$property};
            }
        }

        return $patch;
    }
964132
public static function makeFromJson(JsonResponse $json)
    {
        $content = $json->getContent();

        // If the contents of the JsonResponse does not starts with /**/ (typical laravel jsonp response)
        // we assume that it is a valid json response that can be decoded, or we just use the raw jsonp
        // contents for building the response
        if (! Str::startsWith($json->getContent(), '/**/')) {
            $content = \json_decode($json->getContent(), true);
        }

        $new = static::create($content, $json->getStatusCode());

        $new->headers = $json->headers;

        return $new;
    }
514627
public static function create(array $json)
    {
        $setBadgeResponse = new SetBadgeResponse();
        $setBadgeResponse->setStatusCode($json['status_code']);
        $setBadgeResponse->setStatusMessage($json['status_message']);

        return $setBadgeResponse;
    }
1336845
public static function jsonDeserialize( $json ) {
		return new self(
			$json['id'],
			$json['type'],
			$json['action'],
			$json['timestamp'],
			$json['user'],
			PageIdentifier::jsonDeserialize( $json['pageidentifier'] ),
			$json['comment'],
			$json['details']
		);
	}
976700
public static function deserialize(string $json)
    {
        $deserialized = json_decode($json, true);
        $objects = [];

        return self::decode($deserialized, $objects);
    }
278196
private function jsonToArray($json)
	{
		try {
			$data = json_decode($json, true);
			if(is_array($data)) {
				return $data;
			}
			else {
				$this->error = 'The given data string was not json';
				return [];
			}
		}
		catch(Exception $e) {
			$this->error = $e;
		}
	}
623138
public static function groupResponse($json)
    {
        $fields = Deserialize::_fromJson($json);
        return Deserialize::_groupResponseFromFields($json, $fields);
    }
845912
public static function RawSignedModelFromJson($json)
    {
        $body = json_decode($json, true);
        $signatures = $body['signatures'];

        $rawSignatures = [];
        foreach ($signatures as $signature) {
            $signatureSnapshot = null;
            if (array_key_exists('snapshot', $signature)) {
                $signatureSnapshot = $signature['snapshot'];
            }

            $rawSignatures[] = new RawSignature(
                $signature['signer'], base64_decode($signature['signature']), base64_decode($signatureSnapshot)
            );
        }


        return new RawSignedModel(base64_decode($body['content_snapshot']), $rawSignatures);
    }