Skip to content

Blade directive @json outputs invalid PHP code #56584

@balthild

Description

@balthild

Laravel Version

12.21.0

PHP Version

8.4.6

Database Driver & Version

No response

Description

When calling @json with an array, the closing square bracket ] is missing in the output.

Steps To Reproduce

Blade template:

<script>
    const data = @json([
        'a' => 1,
        'b' => 2,
        'c' => 3,
    ]);
</script>

Compiled output:

<script>
    <?php echo json_encode([
        'a' => 1, 'b' => 2, 'c' => 3) ?>;
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions