javascript check if json file is empty

Solutions on MaxInterview for javascript check if json file is empty by the best coders in the world

showing results for - "javascript check if json file is empty"
Mats
22 Sep 2019
1//First of all JSON fle cannot be completely empty, you need to make sure
2//it has atleast a pair of double curly braces "{}". Otherwise you will
3//get an error.
4
5//import the file system library
6const fs = require('fs');
7
8//Then load it into a varibale
9var webProjects = JSON.parse(fs.readFileSync('webProjects.json'));
10
11// Then the if statement below can be used to check if it is empty
12if(Object.entries(webProjects).length === 0)