Jump to content

JSON/Introduction

From Wikibooks, open books for an open world
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

What is JSON?

JSON is short for "JavaScript Object Notation. It is not a programming language, but a markup language, just like XML. It is not to make apps, but to supplement them. Unlike XML, JSON is much more lightweight. It is based off JavaScript, but can be read by virtually any programming language that exists, since hundreds of libraries exist. A JSON file is simply a list of variables of data.

What can JSON be used for?

JSON is used mainly for web applications, to exchange quick bits of data in a single file. This is not limited to websites, but also online games, for example. It can also be used for other purposes, like for an application to store its settings in a lightweight file. Or, perhaps, it can be used by a game to store a player's data. All types of JavaScript variables are usable here, from integers to arrays.

How does JSON work?

JSON data is stored in a file, which is left as is. It is not compiled into binary code, just left as is. This is the nature of any markup language, not just JSON. It is up the application to open the file, scan the text and pick out the data it needs, and change whatever it needs to change. A developer would use a 'parser library' to do the work of scanning the text and loading certain variables into memory for the application to use. Variables, such as integers are created here and stored in the file. JSON files end with ".json" and are stored wherever the application needs it to be.

Is JSON difficult?

Absolutely not. JSON, for starters is human-readable, so it is easy to get the understanding of it quickly. Syntax is simple and based on JavaScript. It helps to know JavaScript, since JSON is JavaScript. It takes only a day to learn, really, even if you don't know JavaScript.

Are there any prerequisites?

Yes. You need to actually know and understand a programming language, since JSON is only there to compliment your application, not make it. You will need a code editor to continue, like Atom or Visual Studio Code, though any text editor like Notepad will do. You can download both Visual Studio Code and Atom for free. Finally, for whatever programming language you use, you need a parser library to continue.

References

  1. Wikipedia - JSON[1]

Further reading

  1. XML
  2. Markup language
  3. JavaScript
  1. [1]