Json read file

Code examples

12
0

json dump to file

import json

data = {"key": "value"}

with open('data.json', 'w') as jsonfile:
    json.dump(data, jsonfile)
12
0

open json file python

import json

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

json load from file python 3

import json

with open('file_to_load.json', 'r') as file:
  data = json.load(file)
4
0

write json pythonb

import json

with open('data.txt') as json_file:
    data = json.load(json_file)
    for p in data['people']:
        print('Name: ' + p['name'])
        print('Website: ' + p['website'])
        print('From: ' + p['from'])
        print('')
0
0

write json pythonb

>>> jstr = json.dumps(data, ensure_ascii=False, indent=4)
>>> print(jstr)
{
    "item": "Beer",
    "cost": "£4.00"
}
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({});
      }

In other languages

This page is in other languages

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