Get OData $metadata in JSON format
I agreed with the previous answer. This isn't supported by the specification but some OData frameworks / libraries are about to implement this feature.
I think about Olingo. This is could be helpful for you if you also implement the server side. See this issue in the Olingo JIRA for more details:
- OLINGO-570 - https://issues.apache.org/jira/browse/OLINGO-570
Hope it helps you, Thierry
You can use jQuery to get the relevant information from an OData service $metadata.
Take for example:
You write a unit test to check the OData entities property names matches with your application entities. Then you have to retrieve the properties of the OData entity.
$.ajax({
type: "GET",
url: "/destinations/odata-service/$metadata",
beforeSend: function() {
console.log("before send check");
},
dataType: "xml",
contentType: "application/atom+xml",
context: document.body,
success: function(xml) {
console.log("Success ResourceTypes");
var ODataTypeINeed = $(xml).find('EntityType').filter(function(){
return $(this).attr('Name') == 'ODataTypeINeed'
});
$(ODataTypeINeed).find('Property').each(function() {
console.log($(this).attr('Name')); //List of OData Entity properties
});
},
error: function(err) {
console.log(err);
}
});
As an alternative to ?$format=json
, you could also just set the following two headers :
Accept: application/json
Content-Type: application/json; charset=utf-8
I'm not sure which is the minimum Odata version required, but this works perfectly for me on Microsoft Dynamics NAV 2016, which uses Odata v4.
The $metadata
document is in the CSDL format, which currently only has an XML representation. (As a side note, if you do want to request the json format for a different kind of OData payload, make sure the format
query token has a $
in front of it: $format=json
.)
So, no it is not possible. You can, however, get the service document in JSON, which is a subset of the $metadata document:
http://odata.informea.org/services/odata.svc?$format=json
This won't have type information, but it will list the available entry points of the service (i.e., the entity sets).