1
votes

I am using JMeter and i am currently facing this issue.

I want to perform a POST request to an API function but somehow when it gets sent to the call, my body data doesnt send in JSON format.

This is the body data sent

{
    "project_id": "2",
    "name": "Jaya Jadon",
    "phone": "0123456789",
    "email": "[email protected]",
    "remarks": "",
    "co_applicants":[
        {
            "name": "Wongg Feig Uncle",
            "phone": "0123476798",
            "email": "[email protected]"
        },
        {
            "name": "Wineg Feie Father",
            "phone": "0123496897",
            "email": "[email protected]"
        }
    ],
    "documents": [
        {
            "booking_form": "",
            "consent_form": [   
                "https://www.jjj.com/CF1.jpg"
            ],
            "ic_passport_no":[
                "https://www.jjj.com/IC1.jpg"
            ],
            "additional": ""
        }
    ]
}

But this is what gets sent to when the POST request is sent

{
    "{\r\n\t\"project_id\"" => ">\"2\",\r\n\t\"name\"=>\"Jaya Jadon\",\r\n\t\"phone\"=>\"0123456789\",\r\n\t\"email\": \"[email protected]\",\r\n\t\"remarks\": \"\",\r\n\t\"co_applicants\":[\r\n\t\t{\r\n\t\t\t\"name\": \"Wongg Feig Uncle\",\r\n\t\t\t\"phone\": \"0123476798\",\r\n\t\t\t\"email\": \"[email protected]\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"name\": \"Wineg Feie Father\",\r\n\t\t\t\"phone\": \"0123496897\",\r\n\t\t\t\"email\": \"[email protected]\"\r\n\t\t}\r\n\t],\r\n\t\"documents\": [\r\n\t\t{\r\n\t\t\t\"booking_form\": \"\",\r\n\t\t\t\"consent_form\": [\t\r\n\t\t\t\t\"https://www.jjj.com/CF1.jpg\"\r\n\t\t\t],\r\n\t\t\t\"ic_passport_no\":[\r\n\t\t\t\t\"https://www.jjj.com/IC1.jpg\"\r\n\t\t\t],\r\n\t\t\t\"additional\": \"\"\r\n\t\t}\r\n\t]\r\n}",
                   "format" => "json",
               "controller" => "v1/lp_developer_referrals",
                   "action" => "create"
}

And this is what I am expecting to get

{
       "project_id" => "2",
             "name" => "Jaya Jadon",
            "phone" => "0123456789",
            "email" => "[email protected]",
          "remarks" => nil,
    "co_applicants" => nil,
        "documents" => [
        [0] {
              "booking_form" => nil,
              "consent_form" => [
                [0] "https://www.jjj.com/CF1.jpg"
            ],
            "ic_passport_no" => [
                [0] "https://www.jjj.com/IC1.jpg"
            ],
                "additional" => nil
        }
    ],
           "format" => "json",
       "controller" => "v1/lp_developer_referrals",
           "action" => "create"
}

Can someone explain to me why my Jmeter is not taking my body data as json objects?

2

2 Answers

1
votes

JMeter should send data "as is", double check the following configuration:

  1. Make sure Use multipart/form-data for HTTP POST box is not checked in the HTTP Request sampler (or in the HTTP Request Defaults)
  2. Make sure you have HTTP Header Manager configured to send Content-Type header with the value of application/json

More information: REST API Testing - How to Do it Right

0
votes

Please, try to add a "HTTP Header Manager" with a "Content-Type" with a value "application/json" before your requests, or inside them. Tell us if the behavior is correct.