With the upcoming WCF Web API, is there any way to control JSON output?
I'd like to change the casing and perhaps suppress that certain properties are included when a class is being serialized.
As an example, consider this very simply class:
[XmlRoot("catalog", Namespace = "http://api.247e.com/catalog/2012")]
public class Catalog
{
[XmlArray(ElementName = "link-templates")]
public LinkTemplate[] LinkTemplates { get; set; }
}
As you can see, I've added various XML attributes to it in order to control how it's serialized in XML. Can I do the same (or something else) for JSON?
For reference, here's a sample output in XML:
<catalog xmlns="http://api.247e.com/catalog/2012"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<link-templates>
<link-template href="http://localhost:9000/search/?criterion={criterion}"
rel="http://docs.247e.com/rels/search"/>
</link-templates>
</catalog>
For JSON, the equivalent result is this:
{
"LinkTemplates":
[
{
"Href":"http:\/\/localhost:9000\/search\/?criterion={criterion}",
"Rel":"http:\/\/docs.247e.com\/rels\/search"
}
]
}
However, I'd like to change the casing of the properties, so I'd prefer something like this instead:
{
"linkTemplates":
[
{
"href":"http:\/\/localhost:9000\/search\/?criterion={criterion}",
"rel":"http:\/\/docs.247e.com\/rels\/search"
}
]
}
A way to strip away certain class properties would also be nice.