DEV Community

Cover image for All you need to know about JSON in 5 minutes
JavaScript Room
JavaScript Room

Posted on

All you need to know about JSON in 5 minutes

Hi! I've never thought that JSON can be a topic for a standalone tutorial/post. But recently I got this suggestion from one of my followers on Instagram and decided to make a quick overview of JSON. I actually think now that it might be useful for some devs. So I recorded the 5 minutes video:

You also can get through the points by yourself, it's not difficult for understanding anyway. Let's write it down:

JSON (JavaScript Object Notation) is a lightweight format for storing and transporting data. It's heavily used on modern web.

Syntax

  • File extension is ".json"
  • Root element must be an object or an array
  • All keys must be double-quoted
  • String values must be double-quoted (escape double quotes in the value)
  • Number and boolean values must NOT be double-quoted
  • Comments are not supported by design
  • No trailing commas

A browser's environment, as well as Node.js, has the global object JSON working with this format. Basically, you need to know just two its methods:

  • JSON.parse(argument): string -> object/array
  • JSON.stringify(argument): object/array -> string
// examples
JSON.parse("{\"key\": \"value\"}"); // { key: "value" }
JSON.stringify({key: "value"}); //"{"key":"value"}"

That's what you need to know about JSON. Did I miss something important? Please let me know in comments then.

Thanks for watching/reading and welcome to JavaScript Room blog on Instagram, Twitter, Facebook and Telegram!

Top comments (0)