function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mohan s 37mohan s 37 

System.JSONException: Malformed JSON: Expected '{' at the beginning

Hi Friends,
I am getting the following bug while performing test to the apex controller the test class is failed due to the following error can any one please tell me what it is and how to resolve it. "System.JSONException: Malformed JSON: Expected '{' at the beginning of object"
Class.EngagementGraphsController.generateFilterWrapper: line 253, column 1
Class.ChartDrillDownController.getDrilldownPatientsData: line 39, column 1
Class.ChartDrillDownController_Test.patientdataTest: line 86, column 1
Test class:
/*Developer: Rambabu
Description: This is test class of ChartDrillDowncontroller*/
public class ChartDrillDownController_Test{
   static Account testAccount;
    static Contact testContact;
     static User user =[SELECT Id, Name from User WHERE Alias='rbabu'];
      static List<Patient_Enrollment__c> enrollmentTestList = new List<Patient_Enrollment__c>();
    static string chartInput='{"xAxis":"2017-08-01","legend":"TOTAL_INVITED","chartName":"PATIENT_ENGAGEMENT"}';
         static String FromDateString = '2017, 01, 01';
        static String ToDateString = '2017, 08, 09';
       static boolean isDemo = true;
      static date startDate = date.newInstance(2016,08,10);
     static date endDate = date.newInstance(2017,08,10);
    Static String JSONstring = '{"siteIds":["001c000001BydRwAAJ"],"surgeonIds":["003c000000ph8dEAAQ"],"anesthesiologistIds":["003c000000ph8cqAAA"],"procedures":["Axillary Dissection", "Bilateral Mastectomy", "Hiatal Hernia Repair", "Hysterectomy with Staging", "Hysteroscopy D&C", "Lap Cholecystectomy", "Lap-assisted Hysterectomy", "Laparoscopic Supracervical Hysterectomy", "Laparotomy", "Liver transplant"],"HospitalName":["ABC","DEF"],"patientAge":["0-18","18 – 29","30 – 39","40 – 49","50 – 59","60 – 69","70 – 79",">80"],"gender":["Male","Female"],"PainManagementUsed":["ON-Q","Single Injection nerve block","Wound infusion","Local infiltration"]}';
    @testSetup static void setupTestData(){
        testAccount = new Account(Name='testAccount',Site_Display_Name__c='testsite',Start_Date__c=startDate,End_Date__c=endDate,Email__c='',,Status__c='Active',;
        testContact = new Contact(LastName='contact', FirstName='test',AccountId=testAccount.Id,Email='',Role__c='Surgeon',Surgical_Specialty__c='General Surgery');
        for(integer i=0; i<100; i++){
            Patient_Enrollment__c pe = new Patient_Enrollment__c();
            pe.Patient_First_Name__c = 'enrollment';
            pe.Patient_Last_Name__c = 'test'+i;
            pe.Patient_Phone_Number__c = '02064546025';
            pe.Patient_Email__c = '';
            pe.Date_of_Birth__c = date.newInstance(1980,05,12);
            pe.Gender__c = 'Male';
            pe.Patient_Enrollment_Status__c = 'Active - Accepted';
            pe.Gender__c = 'Female';
            pe.Patient_Enrollment_Status__c = 'Active - Invited';
            pe.Surgery_Date__c = date.newInstance(2017,08,1);
            pe.Surgeon__c =;
            pe.Surgery_Type__c = 'Lap BSO';
            pe.Surgeon__c = testContact.Id;
            pe.Anesthesiologist__c = testContact.Id;
            pe.On_Q_Used__c = 'Yes';
            pe.On_Q_pump_Model_used__c = 'CB003';
            pe.Other_Pain_Management_used_if_any__c = 'Wound infusion';
            pe.IsDemo__c = true;
            insert enrollmentTestList;
        system.debug('Patient Enrollment List:'+enrollmentTestList.size());
            SurveyTemplate__c template = new SurveyTemplate__c();
             template.Survey_Template_Name__c  = 'test template';
             template.Available_From__c = '1';
             template.Available_To__c = '3';
             template.Survey_Day_Email_Time__c ='8:00';
             template.Email_Reminder_Time__c = '7:00';
             template.SMS_Reminder_Time__c ='6:00';
             template.Survey_Order__c =2;
           insert template;
        system.debug('Template Id:'+template.Id);
             List<Patient_Survey__c> surveyList = new List<Patient_Survey__c>();
             for(integer i=0; i<10; i++){
                Patient_Survey__c ps = new Patient_Survey__c();
                ps.Name = 'test survey'+i;
                ps.IsDemo__c = true;
                ps.Patient__c = enrollmentTestList[i].id;
                ps.Survey_Name__c =;
                surveyList .add(ps);
       insert surveyList;
        system.debug('SurveyList Size:'+surveyList.size());
       List<Patient_Responses__c> surveyResponseList = new List<Patient_Responses__c>();
       for(integer i=0; i<=10; i++){
           Patient_Responses__c psr = new Patient_Responses__c();
           psr.Patient_Survey__c = surveyList[0].id;
           psr.Selected_Medication_List__c = 'Celebrex';
           psr.Opioid__c = true;
           psr.Section_Name__c = 'side effects';
           psr.Answer__c = 'Dizziness;Constipation';
           psr.IsDemo__c  = false;
       insert surveyResponseList;
        system.debug('Survey response List size:'+surveyResponseList);
    static testmethod void patientdataTest(){
Glyn Anderson 3Glyn Anderson 3

I have checked both 'chartInput' and 'JSONString' with a JSON parser and they are both well formed.  I notice that the methods, getDrilldownPatientsData and getDrilldownPatientsDataForOutcome, take similar arguments in a different order.  Perhaps you are passing in arguments to getDrilldownPatientsData in the wrong order?  Perhaps 'JSONString' should be the fourth agrument to getDrilldownPatientsData, like it is for getDrilldownPatientsDataForOutcome?  Double-check this and see if that's the problem.
Glyn Anderson 3Glyn Anderson 3
Mohan, did you solve the problem?  Was it the order of the arguments?