0

So I'm just wondering what JSON files are, as I lack some knowledge of python files. Please could you also tell me why these are very useful in python, as nearly every python book has them. Thanks.

Edit: I have realized that this are other answers for this problem on stackoverflow which I didn't realize about when I made this quote. Sorry. I cannot delete this post anymore, since answers are already flowing in.

Lunar
  • 108
  • 8
  • 2
    [JSON](https://en.wikipedia.org/wiki/JSON) is just a way to store data in a text file. It's easily readable in lots of languages, and even readable in a basic text editor (though, it may be need to be "pretty printed" first). – gen_Eric Feb 24 '21 at 18:18
  • 1
    check this out : https://www.w3schools.com/whatis/whatis_json.asp – AhmedO Feb 24 '21 at 18:19
  • 1
    Google my friend Google!!! – Sapna Sharma Feb 24 '21 at 18:25

1 Answers1

2

A json file is simply a way to represent data, much like a txt of html file. But the important part is that is has rules to it that can be translated to python objects.

The json file requires an opening {} and at least one tag to be useful, you can read the full documentation here

An example would be this

{ "name":"John", "age":30, "city":"New York"}

and using the json built-in library you can read it effortlessly

import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# the result is a Python dictionary:
print(y["age"])

As to why it is important, it is one of the best ways to send data through the internet since it is supported by the HTTP standard and thus is of great use in building APIs, as well you can use it to store information to be saved when the program stops running.

Rudolf Fanchini
  • 103
  • 1
  • 7