[SalesForce] why i am getting this error when sending data through curl

Error: call to URL
https://cs31.salesforce.com/services/apexrest/CreateLoan/ failed with
status 400, response HTTP/1.1 400 Bad Request Date: Sat, 27 Feb 2016
09:22:27 GMT Set-Cookie:
BrowserId=Dn8n41hbQLCLGe4ztf5mbg;Path=/;Domain=.salesforce.com;Expires=Wed,
27-Apr-2016 09:22:27 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json;charset=UTF-8 Transfer-Encoding:
chunked [{"message":"Unexpected character ('}' (code 125)): was
expecting double-quote to start field name at [line:25,
column:6]","errorCode":"JSON_PARSER_ERROR"}], curl_error , curl_errno
0

Best Answer

You are passing a JSON which is not constructed properly.

  • You have a trailing comma , at the end of last key-value pair, so JSON parse assumes you are going to declare few more variables. But since you abruptly close it with } it fails in parsing it.

  • Assuming by the error message you have error at Line:25 column 6 your json string should look something like below>

Payload:

 json_string = '{ "a":"b", 
 .
 "field": "value",
 } // Line 25

Solution:

Remove the trailing comma and Change it to:

 json_string = '{ "a":"b", 
 .
 .
 "field": "value"
 } // Line 25

and it should work fine

Related Topic