Python Processing JSON Data

JSON stands for the JavaScript Objects Notation. Usually it is a text file which is easily read by the human. Its is a Lightweight format, it is used when data is sent to another via server. Pandas provides the read_json function to reads the json file.

JSON file

{"SR":["1","2","3","4","5" ],
   "Name":["Ram","Shyam","Mohan","Sohan","Geeta"],
   "Roll":["001","002","003","004","005" ],
   
   "AdmissionDate":[ "1/7/2020","1/7/2020","1/7/2020","1/7/2020","1/7/2020"],
   "Class":[ "7”,"7","7","7","7"]}

This file is the demonstration of the JSON .this file save as info.json

Reading JSON File

  1. Upload File
  2. import json
    fro m google.colab import files
    uploaded = files.upload()
    

    Output

    json-data

  3. Decode the File
  4. import io
    data = "information.json"
    io.StringIO(uploaded[data].decode("utf-8"))
    

    Output

    stringIO

  5. Parse file
  6. json.loads(uploaded[file_name].decode("utf-8"))
    

    Output

    parser-file

Subscribe Now