Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KarolGil's avatar

JSON

Hi

How can I check globally if a given incoming request is in JSON format?

And if it isn't, convert the request to JSON and pass it on.

json-> json-> next ...
text-> json-> next ...
0 likes
1 reply
deansatch's avatar
Level 24

This will base it off the headers so if that is ok (i.e. content type is application/json)...

if(request()->isJson()){
	//it is json, continue
}

Please or to participate in this conversation.