Quiz Yourself: Building JSON

Test your knowledge of how to modify the JSON output of a Rails application.

1

Which of the following snippets is a valid JSON response with product’s user into an include section and product_id as a relationship?

A)
{
  "data": [
    {
      "id": 1, "type": "product", "attributes": {
        "user": {
          "id": 2, "attributes": { "email": "stephany@lind.co.uk" }
        }
      }
    }
  ]
}
B)
{
  "data": [
    {
      "id": 1, "type": "product", "relationships": {
        "user": { "id": 2, "type": "user" }
      }
    }
  ],
  "include": [
    {
      "id": 2, "type": "user", "attributes": { "email": "stephany@lind.co.uk" }
    }
  ]
}
C)
{
  "data": [
    { "id": 1, "title": "First product", "user_id": 2 }
  ],
  "include": [
    {
      "id": 2, "type": "user",
      "attributes": { "email": 
      "stephany@lind.co.uk" }
    }
  ]
}
Question 1 of 30 attempted

Get hands-on with 1200+ tech skills courses.