Search code examples
jsonwcf-data-servicesodata

How would an upgrade from verbose JSON to JSON light affect someone who only looks at the data, and not the metadata?


Can anyone explain to me concisely in plain English with a few bullet points what the main differences are between verbose JSON and JSON light for WCF Data Services? I found a document called "JSON light at a glance" by Microsoft, but it's 23 pages long! I don't care about metadata; I only care about the data. I know that JSON light drops the "d" wrapper. Anything else? Are the data types (dates, booleans, etc) sent in the same format?

EDIT: I realize that now Microsoft is now calling JSON light simply "JSON", and JSON verbose is the old, deprecated standard. I am calling the new standard "JSON light" for clarity.


Solution

  • "I don't care about metadata; I only care about the data"

    That's actually a great tagline for JSON Light as a whole :)

    The core principle of JSON light is that servers can cut down on unnecessary metadata in the payload. When a client does need a certain bit of metadata (for example, the URL it should use to edit the entity), the client can generate that URI itself based on common OData URI conventions.

    A client can control how much metadata the server should include in the payload by requesting one of the three different metadata levels:

    • "application/json;odata=fullmetadata" for clients who need to use metadata and don't have a way to compute it themselves
    • "application/json;odata=minimalmetadata" for clients who use metadata but are fine computing it themselves
    • "application/json;odata=nometadata" for clients who don't care about any metadata whatsoever

    If you're writing a client that really doesn't care about any metadata at all (where metadata includes edit links, entity types, property types, stream information, navigation properties, etc.), then you can request "application/json;odata=nometadata" and you'll just get back a bag of properties.

    Even if you don't care about metadata, there are lots of little differences between JSON Verbose and JSON Light. I would strongly recommend relying on a library for this if you're in a language where one is available (for example, in .NET there's the WCF Data Services Client and in Javascript there's datajs or jaydata). Here's a list of a couple differences off the top of my head:

    • In OData v2, DateTimes could be represented using the ticks-based format (e.g., "lastUpdated": "\/Date(1240718400000)\/"), but in v3 JSON only ISO 8601 is supported (e.g., "1992-01-01T00:00:00")
    • There is no "d" wrapper on results payloads anymore.
    • Instead of a "results" wrapper for collection results, there is now a "value" wrapper
    • Instead of "__count" for inline count, JSON Light uses "odata.count"

    As an example, take a look at the differences in the payload produced by this query:

    http://services.odata.org/v3/OData/OData.svc/Products?$inlinecount=allpages&$top=2&$format=application/json;odata=verbose

    Versus this:

    http://services.odata.org/v3/OData/OData.svc/Products?$inlinecount=allpages&$top=2&$format=application/json;odata=nometadata