Always Use a Top Level Key

Learn why we should always use a top-level key.

We'll cover the following...

The example code we’ve seen thus far looks like this:

render json: { widget: widget }

Why didn’t we write only render json: widget?

Doing that would result in a JSON object like so:

{
  "id": 1234,
  "name": "Stembolt",
  "price_cents": 12345
}

There are two minor problems with this as the way our API renders JSON.

  • The first is that we cannot look at this JSON ...