This project has moved and is read-only. For the latest updates, please go here.

DeserializeXmlNode: JSON property name rules mapping to xml

Jun 29, 2010 at 11:05 AM

In JSON, a property name may contain any character except quotes and backslashes. Xml however is much stricter. 

The following statement for instance, fails with the error: "The ' ' character, hexadecimal value 0x20, cannot be included in a name." 

XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"{""test property"": 1}");

Is there a solution for this?



Jul 3, 2010 at 10:56 AM

I can't change the XML specification.

Jul 4, 2010 at 10:36 PM
Edited Jul 4, 2010 at 10:39 PM
That's not much of an answer, now is it? :) One possibility would be to support a generic form of element naming where the elements always have the same name, and the Property Name is provided in an attribute, something like "<z name='test property'>1</z>" for the sample above...?
Feb 12, 2013 at 9:30 AM
We are also experiencing this problem - for example the popular Twitter API returns JSON which looks like this:


Resulting in the following error:
The '/' character, hexadecimal value 0x2F, cannot be included in a name.

Are there any known work arounds to this other than a manual find/replace in the JSON before parsing it? It would be great if we could hook up to an event which gave us a chance to replace these sorts of characters to turn them into valid XML element names during the parsing.