Read json file

Code examples

54
0

python read json file

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)

print(data)
12
0

open json file python

import json

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

write json pythonb

import json

data = {}
data['people'] = []
data['people'].append({
    'name': 'Scott',
    'website': 'stackabuse.com',
    'from': 'Nebraska'
})
data['people'].append({
    'name': 'Larry',
    'website': 'google.com',
    'from': 'Michigan'
})
data['people'].append({
    'name': 'Tim',
    'website': 'apple.com',
    'from': 'Alabama'
})

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)
3
0

read json file python

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)
print(data)

flx = json.dumps(data, ensure_ascii=False, indent=4)
print(flx)
2
0

python json open file

import json

#reading
with open(file_name, 'r') as f:
	data = json.load(f)

#writing
with open(file_name, 'w') as f:
	json.dump(data, f) #use indent to make easyer to read eg. indent = 4
0
0

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) })
0
0

read json data from file

 
// consider your file data is something like json string but aving parse issue 
//that means some additional char is there 
fs.readFile(ROLES_FILE, "utf8", (err, data) => {
      if (err) {
        res.status(403).json({});
      }
      const [localScope, action] = scope.split(".");
      const mapper = JSON.parse(data.toString("utf8").replace(/^\uFEFF/, ""));
      const isAllowed = checkRole(mapper, localScope, action, role);
      if (isAllowed) {
        next();
      } else {
        res.status(403).json({});
      }

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................