Skip to content

[12.x] Refactor: add JSON decoded#58830

Merged
taylorotwell merged 2 commits intolaravel:12.xfrom
alipowerful7:refactor/standardisation-doc
Feb 14, 2026
Merged

[12.x] Refactor: add JSON decoded#58830
taylorotwell merged 2 commits intolaravel:12.xfrom
alipowerful7:refactor/standardisation-doc

Conversation

@alipowerful7
Copy link
Contributor

Fix inconsistent capitalization in PHPDoc comment

Updated the PHPDoc comment for the getData() method to use "JSON decoded" instead of "json_decoded" for consistency with the rest of the codebase.

Changes

  • Changed "json_decoded" to "JSON decoded" in the method's PHPDoc description
  • This aligns with the capitalization style used throughout the codebase

like here:

    /**
     * Get the JSON decoded body of the request.
     *
     * @return array
     */
    protected function json()
    {
        if (! $this->data) {
            $this->data = json_decode($this->body(), true) ?? [];
        }

        return $this->data;
    }
    
        /**
     * Get the JSON decoded body of the response as an array or scalar value.
     *
     * @param  string|null  $key
     * @param  mixed  $default
     * @param  int-mask<JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR>|null  $flags
     * @return mixed
     */
    public function json($key = null, $default = null, $flags = null)
    {
        $flags = $flags ?? self::$defaultJsonDecodingFlags;

        if (! $this->decoded || (isset($this->decodingFlags) && $this->decodingFlags !== $flags)) {
            $this->decoded = json_decode(
                $this->body(), true, flags: $flags
            );

            $this->decodingFlags = $flags;
        }

        if (is_null($key)) {
            return $this->decoded;
        }

        return data_get($this->decoded, $key, $default);
    }
    
        /**
     * Get the JSON decoded body of the response as an object.
     *
     * @param  int-mask<JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR>|null  $flags
     * @return object|null
     */
    public function object($flags = null)
    {
        return json_decode($this->body(), false, flags: $flags ?? self::$defaultJsonDecodingFlags);
    }

@alipowerful7
Copy link
Contributor Author

Un related test failed

Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>
@taylorotwell taylorotwell merged commit fadd8f1 into laravel:12.x Feb 14, 2026
44 of 70 checks passed
@alipowerful7 alipowerful7 deleted the refactor/standardisation-doc branch February 15, 2026 14:57
DarkGhostHunter pushed a commit to DarkGhostHunter/laravel-framework that referenced this pull request Feb 22, 2026
* refactor: add JSON decoded

* Update src/Illuminate/Http/JsonResponse.php

Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants