Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

read json file javascript

fetch("file.json")
    .then(Response => Response.json())
    .then(data => {
        console.log(data);
  		// or whatever you wanna do with the data
    });
Comment

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)
})
Comment

read json file into object javascript

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

js read file json

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

Read JSON File JavaScript

// read remote JSON file in javascript
fetch("https://jsonplaceholder.typicode.com/users")
  .then(function (response) {
    return response.json();
  })
  .then(function (data) {
    for (let i = 0; i < data.length; i++) {
      console.log(data[i]);
    }
  })
Comment

read json file javascript

// using Promise 
fetch("my.json") 
	.then(response => response.json()) 
	.then(parsed => /* parsed contains the parsed json object */); 
 
// or if you can use async/await 
let response = await fetch("my.json"); 
let parsed = await response.json();
Comment

read json file javascript

// using Promise 
fetch("my.json") 
	.then(response => response.json()) 
	.then(parsed => /* parsed contains the parsed json object */); 
 
// or if you can use async/await 
let response = await fetch("my.json"); 
let parsed = await response.json();
Comment

read json file javascript

// using Promise 
fetch("my.json") 
	.then(response => response.json()) 
	.then(parsed => /* parsed contains the parsed json object */); 
 
// or if you can use async/await 
let response = await fetch("my.json"); 
let parsed = await response.json();
Comment

javascript read json from file

<script type="text/javascript" src="data.json"></script>
<script type="text/javascript" src="javascrip.js"></script>
Comment

read json file javascript

// using Promise 
fetch("my.json") 
	.then(response => response.json()) 
	.then(parsed => /* parsed contains the parsed json object */); 
 
// or if you can use async/await 
let response = await fetch("my.json"); 
let parsed = await response.json();
Comment

PREVIOUS NEXT
Code Example
Javascript :: hide div after 5 seconds vue js 
Javascript :: javascript listen array change 
Javascript :: mongodb mongoose aggregate two collections using lookup & format the result set. 
Javascript :: react-native-config 
Javascript :: get position of element in react 
Javascript :: get the whole value of a number javascript 
Javascript :: slice method in js 
Javascript :: how can i convert object to an array javascript 
Javascript :: Map and Filter methods used together 
Javascript :: js check if array is empty 
Javascript :: uncheck checkbox when another is checked javascript 
Javascript :: disable button 
Javascript :: clear element children js 
Javascript :: how to destroy cookie in javascript 
Javascript :: generate random color array javascript 
Javascript :: substr() javascript 
Javascript :: antd react native 
Javascript :: p5js import typescript 
Javascript :: js new array from new set 
Javascript :: javascript debouncing 
Javascript :: flatmap javascript 
Javascript :: jqery first img src 
Javascript :: clear a div 
Javascript :: js combine arrays 
Javascript :: jquery scroll to element in scrollable div 
Javascript :: next js build command 
Javascript :: new variable in loop javascript 
Javascript :: json object check if key exists java 
Javascript :: if variable is string javascript 
Javascript :: momentjs display timezone 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =