json load file code example

Example 1: open json file python

import json

with open('data.txt') as json_file:
    data = json.load(json_file)

Example 2: python json dump to file

import json
with open('data.json', 'w') as f:
    json.dump(data, f)

Example 3: python json load file

import json

# with json load  (file)
info = open('data.json',)
res = json.load(info)
print(res)
print("Datatype after deserialization : " + str(type(res)))
#>>> {'name': 'Dave', 'City': 'NY'}
#>>> Datatype of the serialized JSON data : <class 'dict'>

Example 4: read json file

const fs = require('fs')fs.readFile('./customer.json', 'utf8', (err, jsonString) => {    if (err) {        console.log("File read failed:", err)        return    }    console.log('File data:', jsonString) })

Example 5: read file json

with open('file.txt', 'r') as f:
	data = f.read()