I saw an online project “Interactive Dictionary with Python” and it stored all of the words and their definitions in a Json file. I am learning Python basics from youtube and I’m just curious about What Json is, how a Json file is created and how can I use it in a python project. Can somebody help me out?
I’m guessing that you’ve already googled it and read some explanations, so can you be more specific about what you need further explained?
It’s just a text file written and formatted in a specific, very constrained way, which makes it easy to read/write if you are human and easy to read/write if you are a computer. It’s used for encoding data: it is easier to use a standard format that everyone uses rather than ad-hoc formats. The entirety of the rules about what it has to look like are contained in the hundred or so words, here: http://json.org/
As to how you use it, would need to know context, JSON is a trivially simple thing, and there are like a trillion libraries for reading/writing, and it’s the most common format for transferring data in over networks, so most HTTP libraries have an encoder/decoder built in etc etc
{
"key": <<value>>,
"key": {
"subkey": <<value>>
},
"key": [
{
"key": <<value>>
}
]
}
Where there can be any amount of whitespace as long as closing ] and } are balanced. And where <> can be a number, null, boolean, a string, another key-value pair map (or object), or an array of <>.
Sometimes JSON doesn’t immediately open with {, it can be an array of values like:
["one", "two", 3]
JSON stands for JavaScript Object Notation so any javascript object literal is also valid JSON but expect keys and values to be coerced to String after making use of JSON.stringify
. JS has always allowed you to omit the quotation marks for object keys but they’ve always been Strings, but you have to if it has spaces or starts with a number/symbol or something like that.
JSON is basically a representation of a dataset, or even just 1 piece of data (a single non-object value is not valid JSON for example “hey” without being contained in an array or as a value for a key).