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.

3
  • 2
    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). Commented Feb 24, 2021 at 18:18
  • 1
    check this out : w3schools.com/whatis/whatis_json.asp Commented Feb 24, 2021 at 18:19
  • 1
    Google my friend Google!!! Commented Feb 24, 2021 at 18:25

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

["test"] is also a valid JSON file. It doesn't need {}. Even "test" is valid JSON. See: json.org
Well, I wanted to share more the good practice than another thing but yes json is quite flexible.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.