Below is code to convert xml to json using http://json.codeplex.com/
how to exclude null from JSON? (ie “SessionId”: “null”)
string xml = ""; //see XML value below
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string jsonText = JsonConvert.SerializeXmlNode(doc); //See Json value below
Xml Input
<MyResponse>
<Timestamp>2012-01-07T12:43:29</Timestamp>
<SessionId></SessionId>
</MyResponse>
Json Output
{"MyResponse":{"Timestamp":"2012-01-07T12:43:29","SessionId":null}}
You could have a simple string replace since you are outputting the JSON as a string. Do something like this:
That should replace every occurrence of null with “”.