1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
5
6print(data)
1import json
2
3# with json load (file)
4info = open('data.json',)
5res = json.load(info)
6print(res)
7print("Datatype after deserialization : " + str(type(res)))
8#>>> {'name': 'Dave', 'City': 'NY'}
9#>>> Datatype of the serialized JSON data : <class 'dict'>
1>>> jstr = json.dumps(data, ensure_ascii=False, indent=4)
2>>> print(jstr)
3{
4 "item": "Beer",
5 "cost": "£4.00"
6}
7
1
2// consider your file data is something like json string but aving parse issue
3//that means some additional char is there
4fs.readFile(ROLES_FILE, "utf8", (err, data) => {
5 if (err) {
6 res.status(403).json({});
7 }
8 const [localScope, action] = scope.split(".");
9 const mapper = JSON.parse(data.toString("utf8").replace(/^\uFEFF/, ""));
10 const isAllowed = checkRole(mapper, localScope, action, role);
11 if (isAllowed) {
12 next();
13 } else {
14 res.status(403).json({});
15 }