Search code examples
jsonodataatom-feed

OData Standard element names


I've been looking into the OData standard and would like to update my services to provide this standard and to consume it. I know that for the XML, it uses the ATOM XML standard so the names of the elements, such as id, title, author, etc. must be that exactly - conform to the Atom standard. The JSON format for OData has different names for their elements. Are those required to be that way or can I have my JSON structure use the same names for it's elements as the Atom XML structure?

An example is the link - in Atom it's called link, with an href and rel attribute. The JSON name for this element is __metadata with the key being uri. It seems like those names are standard and can't change. I'm wondering if the root elements, __metadata, resource, etc. are standard, but maybe the internal elements maybe more flexible. Like the title element for the Atom corresponds to the name element in the JSON structure, could I keep the JSON structure to use title instead of name?


Solution

  • The names mentioned in the started for JSON are part of the standard and can't be changed (otherwise clients won't be able to understand the payload OData JSON). This applies to pretty much anything starting with double underscore (so __metadata, __deferred and so on). Also the value of the _metadata property (or any other _ property) is defined by the standard and should exactly match the standard. There are couple of other places where the names are defined by the standard, just read through it. The properties which are not defined by the standard are usually treated as OData properties, so those are defined by the model you're exposing through OData (they are the same as the elements under the m:properties element in OData ATOM). So those are somewhat customizable, by changing the OData model, but then you're changing both ATOM and JSON formats.