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
JPSeaburyJPSeabury 

Getting "System.JSONException: Illegal value for boolean" error when running my test method

I'm trying to write a test method for the following Apex class:
 
// JSON File structure for HealthProjectPocHttpCalloutFlow class.

public class HealthProj {
    
    public ContactInformation contactInformation;
    public String access_token;
    public Integer expires_in;
    public String token_type;
    public DateTime lastSynced;
    
    public class ContactInformation {
        public String FirstName;
        public String LastName;
        public String Email;
        public String X1819_User_ID;
        public Date Birthdate;
        public String phone;
        public String MailingStreet;
        public String MailingCity;
        public String MailingCountry;
        public String MailingState;
        public String MailingPostalCode;   
        public String gender;
        public String version;
        public Boolean Active;
    }    
    
    public static HealthProj parse(String json) {
        return (HealthProj) System.JSON.deserialize(json, HealthProj.class);
    }
}

Here is the test method as written so far:
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

@IsTest
public class HealthProj_Test {
    
    static testMethod void testParse() {
        String json = '{'+
            '   \"contactInformation\": {'+
            '        \"FirstName\": \"Joe\", '+
            '        \"LastName\": \"Tester\", '+
            '        \"Email\": \"bbb@ds.com\",  '+
            '       \"X1819_User_ID\": \"4324324234324242342\",'+
            '        \"Birthdate\": \"2018-07-05\",'+
            '       \"phone\": \"382123\",'+
            '       \"MailingStreet\": \"num\",'+
            '       \"MailingCity\": \"NYC\",'+
            '       \"MailingCountry\": \"USA\",'+
            '       \"MailingState\": \"NY\",'+
            '       \"MailingPostalCode\": \"12345\",'+
            '       \"Gender\": \"M\",'+
            '       \"Active\": \"False\",'+
            '       \"Version\": \"1\"'+
            '   }'+
            '}';
        HealthProj obj = HealthProj.parse(json);
        System.assert(obj != null);
    }
}
Salesforce is giving me a JSON Exception system error with the Boolean form:
 
' \"Active\": \"False\",'+

The full error message is System.JSONException: Illegal value for boolean: False at [line:1, column:421]
Class.System.JSON.deserialize: line 15, column 1
Class.HealthProj.parse: line 32, column 1
Class.HealthProj_Test.testParse: line 27, column 1

I've tried using
 
' \"Active\": \"0\",'+
 
with similar failure results.

 
Best Answer chosen by JPSeabury
Raj VakatiRaj Vakati
Updated code and wokring , 
 
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

@IsTest
public class HealthProj_Test {
    
    static testMethod void testParse() {
        String json = '{'+
            '   \"contactInformation\": {'+
            '        \"FirstName\": \"Joe\", '+
            '        \"LastName\": \"Tester\", '+
            '        \"Email\": \"bbb@ds.com\",  '+
            '       \"X1819_User_ID\": \"4324324234324242342\",'+
            '        \"Birthdate\": \"2018-07-05\",'+
            '       \"phone\": \"382123\",'+
            '       \"MailingStreet\": \"num\",'+
            '       \"MailingCity\": \"NYC\",'+
            '       \"MailingCountry\": \"USA\",'+
            '       \"MailingState\": \"NY\",'+
            '       \"MailingPostalCode\": \"12345\",'+
            '       \"Gender\": \"M\",'+
            '       \"Active\": false,'+
            '       \"Version\": \"1\"'+
            '   }'+
            '}';
        System.debug(json);
        HealthProj obj = HealthProj.parse(json);
        System.assert(obj != null);
    }
}

 

All Answers

Raj VakatiRaj Vakati
try this
 
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

@IsTest
public class HealthProj_Test {
    
    static testMethod void testParse() {
        String json = '{'+
            '   \"contactInformation\": {'+
            '        \"FirstName\": \"Joe\", '+
            '        \"LastName\": \"Tester\", '+
            '        \"Email\": \"bbb@ds.com\",  '+
            '       \"X1819_User_ID\": \"4324324234324242342\",'+
            '        \"Birthdate\": \"2018-07-05\",'+
            '       \"phone\": \"382123\",'+
            '       \"MailingStreet\": \"num\",'+
            '       \"MailingCity\": \"NYC\",'+
            '       \"MailingCountry\": \"USA\",'+
            '       \"MailingState\": \"NY\",'+
            '       \"MailingPostalCode\": \"12345\",'+
            '       \"Gender\": \"M\",'+
            '       \"Active\": \False\,'+
            '       \"Version\": \"1\"'+
            '   }'+
            '}';
        HealthProj obj = HealthProj.parse(json);
        System.assert(obj != null);
    }
}

 
JPSeaburyJPSeabury
Thanks for the quick reply, Raj V. 

That doesn't compile. It generates an "Unexpected token '<'. at line 23 column 1"
Raj VakatiRaj Vakati
try this pls
 
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

@IsTest
public class HealthProj_Test {
    
    static testMethod void testParse() {
        String json = '{'+
            '   \"contactInformation\": {'+
            '        \"FirstName\": \"Joe\", '+
            '        \"LastName\": \"Tester\", '+
            '        \"Email\": \"bbb@ds.com\",  '+
            '       \"X1819_User_ID\": \"4324324234324242342\",'+
            '        \"Birthdate\": \"2018-07-05\",'+
            '       \"phone\": \"382123\",'+
            '       \"MailingStreet\": \"num\",'+
            '       \"MailingCity\": \"NYC\",'+
            '       \"MailingCountry\": \"USA\",'+
            '       \"MailingState\": \"NY\",'+
            '       \"MailingPostalCode\": \"12345\",'+
            '       \"Gender\": \"M\",'+
            '       \"Active\": False,'+
            '       \"Version\": \"1\"'+
            '   }'+
            '}';
        HealthProj obj = HealthProj.parse(json);
        System.assert(obj != null);
    }
}

 
Raj VakatiRaj Vakati
Updated code and wokring , 
 
//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

@IsTest
public class HealthProj_Test {
    
    static testMethod void testParse() {
        String json = '{'+
            '   \"contactInformation\": {'+
            '        \"FirstName\": \"Joe\", '+
            '        \"LastName\": \"Tester\", '+
            '        \"Email\": \"bbb@ds.com\",  '+
            '       \"X1819_User_ID\": \"4324324234324242342\",'+
            '        \"Birthdate\": \"2018-07-05\",'+
            '       \"phone\": \"382123\",'+
            '       \"MailingStreet\": \"num\",'+
            '       \"MailingCity\": \"NYC\",'+
            '       \"MailingCountry\": \"USA\",'+
            '       \"MailingState\": \"NY\",'+
            '       \"MailingPostalCode\": \"12345\",'+
            '       \"Gender\": \"M\",'+
            '       \"Active\": false,'+
            '       \"Version\": \"1\"'+
            '   }'+
            '}';
        System.debug(json);
        HealthProj obj = HealthProj.parse(json);
        System.assert(obj != null);
    }
}

 
This was selected as the best answer
JPSeaburyJPSeabury
Aha! I see now!! Brilliant, thank you!