get json file js code example

Example 1: get json from file python

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('')

Example 2: read json file into object javascript

fs.readFile(filePath, function (error, content) {
    var data = JSON.parse(content);
    console.log(data.collection.length);
});

Example 3: 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)
})

Tags:

Java Example