JSON
Laravel JSON responses set the content type and encode data.
What it is
Laravel JSON responses set the content type and encode data.
When to use it
Use deliberate arrays/resources for APIs.
Syntax
response()->json(["data" => $data]);Example
return response()->json([
"data" => ["amount_cents" => 1250, "currency" => "USD"],
"meta" => ["request_id" => $requestId],
]);Common mistakes
Avoid double-encoding JSON strings; large integers may exceed JavaScript safe integer limits.