JSON light was introduced in Sharepoint Online in April 2014: JSON Light support in REST SharePoint API released. It allows to reduce traffic size by returning less metadata from the server when you use Sharepoint social API and as result perform actions faster. Sharepoint social API may return result in 2 formats: xml and json. In order to get results in json format we need to set Accept HTTP header to “application/json; odata=verbose”. Note on odata=verbose. It tells to the server that it should return maximum available metadata. Before JSON light it was the only option. After introducing JSON light feature the following options became available:
- application/json; odata=verbose
- application/json; odata=minimalmetadata
- application/json; odata=nometadata
Using these options we may reduce metadata returned from server.
Everything works quite well in Sharepoint Online. However on-premise installations there may be problems. Let’s consider the following code which loads sites followed by current user:
This example uses odata=verbose and returns result similar to this:
If we just change odata=verbose to odata=nometadata we will get error, because server will return xml instead of json:
It happens because in order to enable JSON light on-premise additional actions should be done: How to turn on and off the multiple metadata formats for JSON in SharePoint Server 2013. Briefly you need to install Service Pack 1 for Sharepoint 2013 and WCF Data Services 5.6. After that add the following assembly binding redirections to web.config of your web application:
It can be also done using PowerShell script provided in technet article (in this case web.configs of all web applications in your farm will be changed):
and restart IIS. After that we will be able to use odata=nometadata when make requests to the social API:
Note that we not only changed odata to nometadata in accept HTTP header, but also now iterate through data.value instead of data.d.Followed.results. If we will check response in fiddler we will get the following:
If we will compare it with result which was returned for odata=verbose we will see that result is returned in different format (less nested objects) and there is no metadata section now:
In our example with followed sites this is of course minimal overhead, but in other calls it may be significant. Hope that this information will help you if you will face with mentioned problem.