I have been using JSON.Serialize method extensively in one of customer's project. Today salesforce has started rolling out Spring '13 release on sandboxes. My customer's sandbox( cs11) is not listed on https://trust.salesforce.com/trust/maintenance/ but still Spring '13 is available in this sandbox.

I have noticed a change that if I serialize a sObject, Json Serializer doesn't return fields with null value in json. Before Spring '13 release it was working fine.

If this was a needed change to reduce size of serialized json, Salesforce should have made this version specific change or a overloaded method to keep backward compatibility. It has broken 30%-40% of my code that I will need to rewrite.

Salesforce please undo this change.

Current output: [ { "attributes": { "type": "ABC_c", "url": "/services/data/v27.0/sobjects/ABC_c/xxxx" }, "Active__c": false, "Id": "XXXX", "Name": "ABC" }, ]

Old output: [ { "attributes": { "type": "ABC_c", "url": "/services/data/v27.0/sobjects/ABC_c/xxxx" }, "Active_c": false, "FirstName_c": null, "Id": "XXXX", "Name": "ABC" }, ]

  • 1
    Can you just make the class deprecated to version 26.0 and try.I just verified and yes JSON.serialise() no more returns null values Jan 12, 2013 at 14:59
  • 1
    Also only one way i can think of now is if the value is null you may need to explicitly say value=null to get back the same in JSON Account acc=[Select Id,name,Name_Suffix__c from Account where id='001W0000007Ky0Z']; if(acc.Name_Suffix__c!=null) {acc.Name_Suffix__c=null; }System.debug('JSON STRING'+acc); Jan 12, 2013 at 16:07
  • 3
    As Mohith says, all changes can be version specific - you should be able to mark the class as API 26.0 and have nulls encoded.
    – metadaddy
    Jan 12, 2013 at 17:44
  • I am using version 25.0 on my classes still it is not returning null fields in JSON. Can someone from Salesforce Engineering team confirm this issue and expected behavior of this during final roll-out on production instances.
    – user1203
    Jan 13, 2013 at 5:18
  • Stackexchange note; it seems that you have created two accounts on salesforce.stackexchange.com, it would be best to use one. As an answer to your question, to get input from the Salesforce team, I think it would be best to log a case. Jan 13, 2013 at 10:25

1 Answer 1


The Apex development team changed the behavior of the JSON serialization in response to several customer issues.

As you are aware, we will typically version changes to the system behavior where possible, in order to protect backward compatibility. There are situations in which we do not version behavior, however. We made an assumption that JSON parsers would not have an issue not receiving null values, since the information received is not relevant. It's like the junk mail you reflexively throw out when sifting through your mail.

As per your post, it's clear that some parsing strategies depend on null values being included in the JSON output. We apologize that our assumption was incorrect, and that your integration and others were unable to operate with the new version.

We have undone the change for the Spring '13 release. To support the original customer cases that prompted these changes, we will version in the originally intended fix in the Summer release.


Josh Kaplan

Product Manager, Apex Code

  • 1
    Was this added? still not able to get null values with version 28? Am I missing something? Aug 5, 2013 at 6:31
  • I think it takes null values now
    – SEuser
    Jan 6, 2015 at 9:41
  • I can't get any null values. Tried all version from 32 down to 25. No luck.
    – Uwe Heim
    Feb 12, 2015 at 17:45
  • Im still seeing JSON.serialize strip out null parameters even in the latest release? Any insight into a way around this? Mar 12, 2015 at 4:45
  • 1
    @Josh Kaplan why can't you allow the developer to decide the functionality?! This could easily just be an annotation on the class or a parameter on the method. Apex serialization is so half baked it hardly even usable. And not being able to set the serialization property name different from the APEX property is a HUGE issue.
    – NSjonas
    Aug 9, 2015 at 15:58

You must log in to answer this question.

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