Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am pulling data from a SharePoint list with listData.svc, and _metadata represent more than half of the response content.

Is there a way to return list fields only, without the metadata?

Below an example in JSON format, atom has a similar issue. What I really want is the data in bold.

{ "__metadata": { "uri": "http:/.../_vti_bin/listdata.svc/Contacts(2988)", "etag": "W/\"3\"", "type": "Microsoft.SharePoint.DataService.ContactsItem" }, "Contact": "christophe", "EmailAddress": "christophe@usermanagedsolutions.com", "Account": { "__metadata": { "uri": "http://.../_vti_bin/listdata.svc/Accounts(5570)", "etag": "W/\"5\"", "type": "Microsoft.SharePoint.DataService.AccountsItem" }, "Account": "Car Rental Inc" } }

share|improve this question
    
How or where are you handling the response from the data service? Are you handling client-side (ie. javascript) or server-side? –  Alban Jan 5 '12 at 15:29
    
Client side. The objective is to build dynamic pages that respond to user actions. –  Christophe Jan 5 '12 at 17:22

3 Answers 3

up vote 5 down vote accepted

Well, I am not absolutely sure, but I think the answer is: there is no way to skip metadata property. You may of course create a kind of proxy by implementing a custom web service which itself consumes listdata.svc and truncates the "__metadata" property? But it doesn't sound good to me.

You can of couse skip all other unnecessary properties by defining the properties in an explicit way:

/_vti_bin/listdata.svc/Contacts()?$select=Contact,Account

But I suppose, you already do this.

This metadata biest is still there. I hope someone can disprove my answer :)

share|improve this answer
    
Right, I explicitly select the fields. And because Account is a lookup, SharePoint serves two sets of metadata, one for the current list and one for the lookup list. –  Christophe Jan 5 '12 at 18:35
3  
I just wanted to confirm that you cannot exclude the __metadata property as this is an important component of the RESTfulness of the ListData service. Remember that in REST-based services the URL represents the entity and when consuming a RESTful service you need to 2 things: has the entities state changed? (etag) and what is the unique URL that represents the entity? This is so that I can perform HTTP operations on it and its sub-properties and notify the UI if someone else has chanaged the item (mismatched etag). –  Robert Kaucher Jun 5 '13 at 1:20

This is a shot in the dark. As you said in your comment, you are building pages dynamically. I am not sure about this, but, I tend to think that if you have a view for the page that the data will be returned OUTSIDE of the metadata as you would expect. I have experienced this with lists.asmx, in that, field/column information or metadata would be returned in metainfo columns. If the fields were present in a view, then these fields were not apart of the metainfo columns. For my unique case, I created a specific view for my scenario, so my particular fields would appear normally in my response results. Again, my scenario has to do with lists.asmx, and I wonder if this could be similar. I wish I could give something concrete, but like I mentioned in the beginning, it is a shot in the dark.

If my theory is correct, verify that the view for this page contains the fields that you want returned in the results.

share|improve this answer
    
I'll try that. lists.asmx can target a view, but I don't know if the REST API can do it. –  Christophe Jan 5 '12 at 17:57
    
Apparently you cannot select a view with REST services, only use filters on the whole list. –  Christophe Jan 5 '12 at 21:17
    
Indeed, I targeted a specific view that basically contained all of the fields that needed to be returned in the response, and I would dynamically generate a view with the fields I needed if the view did not exist. In this case, lists.asmx and views.amsx were very powerful, but a pain in the arse to use. –  Alban Jan 5 '12 at 23:01
    
However, for other instances, I make substantial use of a service that encapsulates listdata.svc. The great thing is that you get a DataContext with stongly-typed objects when you use listdata.svc. However, I'm not sure you can achieve this with dynamic lists. With my experience, anytime you make a change to a list or library, the data service tied to the datacontext will have to be updated. –  Alban Jan 5 '12 at 23:01
    
What are you using to dynamically create these pages? Have you verified that the default view for your dynamically-created page or pages actually contain the fields for which you are looking? –  Alban Jan 6 '12 at 0:36

Your question implies that you already know the specific item. That makes it easier to isolate the data you want. Each of the lines shown will return a text response as shown below assuming that these are not "special" fields like choice, lookup, etc.

This URL will return christophe

http:/.../_vti_bin/listdata.svc/Contacts(2988)/Contact/$value

This URL will return christophe@usermanagedsolutions.com

http:/.../_vti_bin/listdata.svc/Contacts(2988)/EmailAddress/$value

This URL will return Car Rental Inc

http:/.../_vti_bin/listdata.svc/Contacts(2988)/Account/$value

share|improve this answer
    
I only pasted one item as an example, but I am actually returning a set of items. This would definitely work great for a single value! –  Christophe Oct 13 '13 at 0:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.