DEV Community

Cover image for Parsing Json File Using Python
Fiki Maulana
Fiki Maulana

Posted on

Parsing Json File Using Python

Here Some script to parsing json file using Python :

data_barang.josn

{
  "data":{
    "row" : [
      {
        "id":"10001",
        "nama_barang":"Air Mineral",
        "stok":"7",
        "satuan":"Botol",
        "harga":"5000"
      },
      {
        "id":"10002",
        "nama_barang":"Minyak Goreng",
        "stok":"10",
        "satuan":"Pcs",
        "harga":"20000"
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

tania.py

import json
json = json.loads(open('data_barang.json').read())
value = json['data']['row']

for i in range (len (value)):
    print("=================================")
    print("Nomor        : ",i+1)
    print("Id Barang    : ",value[i]['id'])
    print("Nama Barang  : ",value[i]['nama_barang'])
    print("Stok         : ",value[i]['stok'])
    print("Satuan       : ",value[i]['satuan'])
    print("Harga        : ",value[i]['harga'])
    print("=================================")
Enter fullscreen mode Exit fullscreen mode

Result

Alt Result

Top comments (0)