3

I am passing the below JSON structure using POST method to a apex service:

I get an error at line where the codes variable ends

{
"PId" : "345",
"Description" : "test",
"Codes" :[
    {
    "Code" : " ",
    "qw" : " ",
    "qwe" : " ",
    "Desc" : " ",
    "RT": " ",
    } ], <- Error at this line 
"AccountName" : "Account 001",
"AccountNumber" : "123333" ,
"Address" : "NY",
} 

Error:

System.JSONException: Unexpected character ('}' (code 125)): was expecting double-quote to start field name at [line:14, column:3]

Am I forming the JSON correctly ?

4
  • Is it not the extra comma you have at line 14? Also, line 10 seems to be the same. Strongly suggest you use this JS code quality tool for these niggly errors.
    – TSmith
    Commented Apr 7, 2017 at 15:46
  • Does this tool correct the JSON Structucture?
    – SfdcBat
    Commented Apr 7, 2017 at 15:50
  • Lets not get carried away... It will clearly state the formatting errors line by line, unlike SF error reporting. An alternative, JSON Formatter & Validator will highlight the errors and provide hints and tips. Cool tool too.
    – TSmith
    Commented Apr 7, 2017 at 15:52
  • @TSmith jshint is not appropriate here. JSON is more strict than JavaScript. Trailing commas are allowed in JavaScript, but not in JSON. A more appropriate tool would be JSONLint or similar.
    – sfdcfox
    Commented Apr 7, 2017 at 15:54

1 Answer 1

4

The trailing "," is not allowed. The final element in an object or array must not have a comma after it.

{
"PId" : "345",
"Description" : "test",
"Codes" :[
    {
    "Code" : " ",
    "qw" : " ",
    "qwe" : " ",
    "Desc" : " ",
    "RT": " "
    } ],
"AccountName" : "Account 001",
"AccountNumber" : "123333" ,
"Address" : "NY"
} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .