Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check if json file is empty

//First of all JSON fle cannot be completely empty, you need to make sure
//it has atleast a pair of double curly braces "{}". Otherwise you will
//get an error.

//import the file system library
const fs = require('fs');

//Then load it into a varibale
var webProjects = JSON.parse(fs.readFileSync('webProjects.json'));

// Then the if statement below can be used to check if it is empty
if(Object.entries(webProjects).length === 0)
Comment

PREVIOUS NEXT
Code Example
Javascript :: materialize for react 
Javascript :: javascript get element by custom attribute 
Javascript :: navigating programatically react 
Javascript :: javascript querySelectorAll id ends with 
Javascript :: javascript remove character from string 
Javascript :: js desktop notification 
Javascript :: javascript domcontentloaded 
Javascript :: react how to create range 
Javascript :: axios async get 
Javascript :: set variable to object without editing old object js 
Javascript :: jquery validate checkbox before submit 
Javascript :: convert date to millisecond in javascript 
Javascript :: jquery select clear options 
Javascript :: javascript count instances in string 
Javascript :: clear whitespace from object javascript 
Javascript :: concat array of objects javascript 
Javascript :: xmlhttprequest get request 
Javascript :: sum of digits in a whole number javascript 
Javascript :: javascript pass all arguments to another function 
Javascript :: get document jquery 
Javascript :: getting href value in jquery 
Javascript :: javascript array filter with multiple id 
Javascript :: js localstorage 
Javascript :: Check ratelimit discord js 
Javascript :: if else short term 
Javascript :: hide browser address bar javascript 
Javascript :: regex for email 
Javascript :: react 404 page not found 
Javascript :: Confirm the Ending 
Javascript :: website edit js 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =