I need to remove the extra bracket from the JSON Body which i am sending in a Request:

Please find the JSON in below:


I just Want to remove the extra Square Bracket Outside in the JSON Format:

Below Code For JSON Generation

public static void frameCaseWebService(){

    //Query out the data from Salesforce database.
    List<Case> caseList = [Select id From Case Where Owner.Name ='WMG Ops - Follow Up' AND Has_Hit_Follow_Up__c = False AND 
                           Type = 'New Application' AND Sub_Type__c IN ('ML VA','ML EA','ML FA','Fee Based ML VA')];


    Case_Associated_Document__c[] caseAssoDoc = [SELECT Id,Service_Request__r.Id, Document_Id__c FROM Case_Associated_Document__c WHERE Service_Request__r.Id = :caseList];

    Map<String,List<String>> mapForJson = new Map<String,List<String>>();

    for(Case_Associated_Document__c caseAssoDoc1 :caseAssoDoc){
            mapForJson.put(caseAssoDoc1.Service_Request__r.Id,new List<String>{caseAssoDoc1.Document_Id__c});

    List<CaseDetails> lst = new List<CaseDetails>();
    for( String obj : mapForJson.keySet() ){
        lst.add(new CaseDetails(obj,mapForJson.get(obj)));

    String jsonBody = json.serialize(lst);
  • There is no extra bracket. I think you are running into X-Y Problem. Can you post exact requirement/issue ? Sep 18, 2019 at 8:26
  • The Extra Square[ ] Bracket Outside of the JSON Starting From { "securianDocNumbers"is creating problem for my request. it is saying bad request
    – user74188
    Sep 18, 2019 at 8:28
  • Wont that make JSON as invalid? Sep 18, 2019 at 8:29
  • Sorry : I just Check I am getting the error : 14:06:19:439 USER_DEBUG [303]|DEBUG|responseBody=={"httpStatus":400,"httpRequestUri":"/SfsImagingServices/Documents/followup/annuity","message":"JSON parse error: Cannot deserialize instance of com.minnesotamutual.wmg.sfsimaging.client.services.beans.DocumentsFollowupRequest out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.minnesotamutual.wmg.sfsimaging.client.services.beans.DocumentsFollowup
    – user74188
    Sep 18, 2019 at 8:37

1 Answer 1


The "extra bracket" reflects that you potentially don't just have a single record but could have many records - an array. If the receiving service only accepts one record at a time then you will have to make multiple send requests:

for( String obj : mapForJson.keySet() ){
    CaseDetails cd = new CaseDetails(obj,mapForJson.get(obj))
    String jsonBody = json.serialize(cd);
    // Send the JSON here
  • Thanks it Works
    – user74188
    Sep 18, 2019 at 14:49

You must log in to answer this question.