Answers for "read json data from file"

63

python read json file

import json

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

print(data)
Posted by: Guest on April-08-2020
2

extract data from json file python

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'>
Posted by: Guest on April-19-2021
0

write json pythonb

>>> jstr = json.dumps(data, ensure_ascii=False, indent=4)
>>> print(jstr)
{
    "item": "Beer",
    "cost": "£4.00"
}
Posted by: Guest on November-29-2019
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({});
      }
Posted by: Guest on December-16-2020
-1

write json pythonb

>>> import json
>>> data = {'people':[{'name': 'Scott', 'website': 'stackabuse.com', 'from': 'Nebraska'}]}
>>> json.dumps(data, indent=4)
{
    "people": [
        {
            "website": "stackabuse.com", 
            "from": "Nebraska", 
            "name": "Scott"
        }
    ]
}
Posted by: Guest on November-29-2019

Code answers related to "read json data from file"

Code answers related to "Javascript"

Browse Popular Code Answers by Language