+ Start a Discussion
DeepikareddyDeepikareddy 

Json Generator , create generator in salesforce

system.jsonGenerator jpp =  json.CreateGenerator(true);
         
            jpp.writeStartobject();
        
     
            
             jpp.writestringfield('Name',null);
       
            
          jpp.writeEndobject();
 
 
 
          jsonstring1 = jpp.getAsString();

how go get the value of the name as null in the jsonformat :
i.e  
 
              { "Name" : null }

  can anybody suggest how to get the value .
Best Answer chosen by Deepikareddy
Deepak_KumarDeepak_Kumar
Hi Deepika,
Try this one to get the name as null.
 
system.jsonGenerator jpp =  json.CreateGenerator(true);
jpp.writeStartobject();
// jpp.writestringfield('Name',null); // Cannot use to wtite null value.
jpp.writeNullField('Name');
jpp.writeEndobject();

String jsonstring1 = jpp.getAsString();
System.debug(jsonstring1);

If this solves your problem. Mark this as best answer and solved.
Thanks.
Deepak