Databases

JSON: Shape your data

The format every app, game save and API speaks.

6 chapters · 22 lessons · free

Try a free lesson Create your free account

What you will learn

1. Hello, JSON

What JSON is, how an object is written, and the two mistakes everybody makes at first.

  • Your first object Try it A JSON object is a set of "name": value pairs between { and }.
  • Add more facts Exercise Pairs are separated by commas. Numbers have no quotes; text always has double quotes.
  • The name without quotes Debug In JSON, names always have double quotes: "name", never name.
  • One comma too many Debug No comma after the last pair (or the last item in a list). It is the most common JSON mistake in the world.
  • Quick check Quiz Objects: {}, pairs: "name": value, commas between pairs, never after the last.

2. Six kinds of values

Text, numbers, true and false, null, and objects inside objects. Each one has its own rules.

  • Meet every type Try it Six types: text, number, true/false, null, object and list. Only text has quotes.
  • A settings file Exercise true, false and null are words without quotes. "true" in quotes would just be text.
  • True or true? Debug true, false and null are always lowercase in JSON.
  • Numbers are not text Exercise 25 is a number. "25" is text. Programs treat them very differently.
  • Quick check Quiz Text in quotes, numbers without, and the words true, false and null in lowercase.

3. Lists and nesting

Lists hold many values in order, and objects can live inside objects. This is how real data is shaped.

  • Your first list Try it A list is [a, b, c]: values in order, commas between, none after the last.
  • A leaderboard Exercise A list of objects with the same names is the shape of almost every list in an app: users, posts, songs, scores.
  • The missing comma Debug List items, like object pairs, are separated by commas.
  • Objects inside objects Exercise Objects and lists can hold other objects and lists, as deep as you need.
  • Quick check Quiz Lists [ ] for many things, objects { } for one thing, and both can nest.

4. JSON in real apps

Your JSON powers little apps here: a profile card, a playlist, a weather widget and a shop. Change the data, and the app changes.

  • Power a profile card Try it Apps draw what the JSON says. Change the data, and the screen follows.
  • Build a playlist Exercise A list of objects plus a few fields around it: the shape of a playlist, a feed, a shopping cart.
  • Answer like a weather API Exercise An API answer is just JSON with an agreed shape. When both sides agree on the shape, they can talk.
  • The shop that would not open Debug One small JSON mistake breaks the whole file, and the app gets nothing. That is why valid JSON matters.
  • Quick check Quiz Apps load JSON and draw it. One agreed shape, zero mistakes, and everything works.

5. JSON exam

Eight questions about everything in this course. Pass with 6 right answers.

  • The JSON exam Exam You can read, write and fix JSON, and shape data the way real apps and APIs do.

6. Final project

Design the data for an app of your own, and send it for review. A real person checks it and answers you.

  • The data for your own app Final project Designing the data is the first step of every real app. You just did it.

How the course works

You learn by doing: each lesson explains one idea, then you write real code in the editor and see the result right away. The first lesson is free to try without an account; sign up to save your progress and continue.

  • Try it

    Change working code and see the result immediately.

  • Exercise

    Complete a task. A checklist confirms each requirement as you type.

  • Debug

    Fix code that is broken on purpose, and learn why it failed.

  • Quiz

    Check your understanding at the end of a chapter.

More in Databases