2 months ago

Form Request Validation for JSON Parameter

Posted 2 months ago by Nael.Saeed

Hi there,

I have an AJAX request sent to my API. This request has a parameter that should contain a JSON formatted data. I want to validate that it is actually JSON. Laravel form request has a 'json' validation rule, but the problem I am facing is that the parameter that I want to validate for JSON gets converted into an array before validation. So how am I supposed to prevent this conversion and do the validation?

Example request data:

    "id": 1,
    "name": "John",
    "json_data": {
        "data1": [

        "data2": [



 * Get the validation rules that apply to the request.
 * @return array
public function rules()

    return [
        'id' => [
        'title' => [
        'json_data' => [

Please sign in or create an account to participate in this conversation.