Answers for "parse a json file"

PHP
66

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
1

read json from file js

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)
})
Posted by: Guest on April-30-2021
12

javascript parse json

const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
Posted by: Guest on May-20-2020
1

parse local json file

// pure javascript
let object;
let httpRequest = new XMLHttpRequest(); // asynchronous request
httpRequest.open("GET", "local/path/file.json", true);
httpRequest.send();
httpRequest.addEventListener("readystatechange", function() {
    if (this.readyState === this.DONE) {
      	// when the request has completed
        object = JSON.parse(this.response);
    }
});
Posted by: Guest on November-18-2020

Browse Popular Code Answers by Language