1

I am considering using the collection+json media type in a project. However, after reading the docs I can't figure out what's the deal with items that have associations.

Given this items list, what should I do if I also need to list, i. ex., a list of gifts you'll get with the product? Should I just add another items list within each item?

"items": [
  {
    "href": "/products/1",
    "data": [
      {
        "name": "name",
        "value": "My product"
      }, 
      {
        "name": "price",
        "value": "100.0"
      }
    ]
  }
]
  • I will leave this question open just in case someone has an answer, but after spending some time reading the discussions forums of collection+json, I can confirm that the `items` array is not supposed to have nested data. This is [one of the threads](https://groups.google.com/forum/?hl=en#!topic/collectionjson/l4V3jZkJMaA) where this issue is discussed. – Carles Jove i Buxeda Sep 24 '14 at 07:37

1 Answers1

1

After many digging and reading through the Discussion Group, it seems that the inline extension is the answer.

{ 
  "collection" :
    {
      "version" : "1.0",
      "href" : "http://example.org/posts/",

      "items" : [
        {
          "href" : "http://example.org/posts/1",
          "data" : [
            { "name" : "name", "value" : "My product" },
            { "name" : "price", "value" : "100.00" }
          ],
          "links": [
            { "rel": "gifts", "href": "http://example.org/gifts/1,2,3,4", "length": 4, "inline":true }
         ]
       }
    ],
    "inline": {
      "http://example.org/gifts/1,2,3,4": { /* embedded collection+json */ }
    }
  }
}