<jupyter_start><jupyter_text>https://realpython.com/python-json/  What is JSON?JSON stands for JavaScript Object NotationJSON is a lightweight data-interchange formatJSON is "self-describing" and easy to understandJSON is language independent **JSON uses JavaScript syntax, but the JSON format is text only.Text can be read and used as a data format by any programming language.  Exchanging DataWhen exchanging data between a browser and a server, the data can only be text.JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server.We can also convert any JSON received from the server into JavaScript objects.This way we can work with the data as JavaScript objects, with no complicated parsing and translations.  The community at large adopted JSON because it’s easy for both humans and machines to create and understand.  What is json?<jupyter_code>data = {
    "firstName": "Jane",
    "lastName": "Doe",
    "hobbies": ["running", "sky diving", "singing"],
    "age": 35,
    "children": [
        {
            "firstName": "Alice",
            "age": 6
        },
        {
            "firstName": "Bob",
            "age": 8
        }
    ]
}
data
import json<jupyter_output><empty_output><jupyter_text>Serialized the data<jupyter_code>data_json_s = json.dumps(data)
data_json_s<jupyter_output><empty_output><jupyter_text>Deserialized the data<jupyter_code>data = json.loads(data_json_s)
data<jupyter_output><empty_output><jupyter_text>json read and write functions<jupyter_code>def write_json(addr,data):
    with open(str(addr), "w") as write_file:
        json.dump(data, write_file)
def read_json(addr):
    with open(str(addr), "r") as read_file:
        data = json.load(read_file)
    return data
!ls
write_json("m.json",data)
data = read_json("m.json")
data<jupyter_output><empty_output><jupyter_text>Real world data.<jupyter_code>data = read_json('data.json')
data
data.keys()
data['conformsTo']<jupyter_output><empty_output><jupyter_text>visualizing data in pandas<jupyter_code>import pandas as pd
data_pd = pd.DataFrame(data['dataset'])
data_pd.head()<jupyter_output><empty_output><jupyter_text>We can have any valid PYTHON data type as a json<jupyter_code>kfio = {'hemant': [{"gaurav":[[1,2,3,4]]}]}
kfio
write_json("f.json",kfio)
read_json("f.json")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10911424903722722, 'fraction_numerical': 0.0034231921266581087, 'mean_word_length': 4.874371859296482, 'pattern_counts': {'":': 10, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '103551', 'license': 'Apache-2.0', 'n_tokens_mistral': 773, 'n_tokens_neox': 758, 'n_words': 218, 'path': 'json.ipynb', 'repo_name': 'raotnameh/json_tutorial', 'size': '2337'}