Teaching Kids Programming – What is JSON? Simply Explained | ninjasquad
Teaching Kids Programming: Videos on Data Structures and Algorithms
Explaining JSON to Kids
JSON – JavaScript Object Notation. This is a lightweight data interexchange format that we use to store and transport the data, which is most commonly used in client/server applications.
JSON is easy to understand and also easy to parse and generate by computers (We have efficient algorithms to encode/decode or serialize/de-serialize JSON).
A JSON consists of an object or an array. However, some standards allow JSON to contain a value type: single string, number or true, false, null.
- “{}” – this is a valid JSON string that contains an empty object.
- “[]” – this is a valid JSON string that contains an empty array.
- “‘1′” – this is a valid JSON string that contains a number.
- “‘true’” – this is a valid JSON string that contains the constant/literal true.
- “‘false’” – this is a valid JSON string that contains the constant/literal false.
- “‘null’” – this is a valid JSON string that contains the constant/literal null.
- “‘hello’” – this is a valid JSON string that contains a single word e.g. “Hello”
An object is like a dictionary that has key-value pairs. The keys have to be within double-quotes. A value could be an object, an array of value-type, a number, a string, or constants.
{ "foo": { "bar": { "tah": [1, 2, 3], "ahx": "abc", "kkk": true, "xyz": ["abc", 123, { "foo": 123 }] } } }
Array elements and key-value pairs are delimiter by comma.
In Python, we can import json and it provides dumps to serialize an variable to a JSON string. And use the loads function to parse a JSON string to a variable.
import json a = json.loads("{}") b = json.dumps(a) # "{}"
Does JSON Support Comments?
JSON doesn’t support comments. Everything in JSON is data.
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading…
506 words
Last Post: MS SQL Server Database: Is It Possible to Identify the Corruption?
Next Post: Teaching Kids Programming – Concatenation of Consecutive Binary Numbers
Source: Internet