GWibisono

read json

Mar 31st, 2026
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.72 KB | Source Code | 0 0
  1. var fs = require('fs');
  2.         var path = require('path'); // Better for cross-platform paths
  3. var _folderData =  parameters['Folder Data'] || '/data/srpg';    
  4.         let folderPath = process.cwd() + _folderData;//_folderData should be custom
  5.         let fileOpen = path.join(folderPath, filename + ".json");
  6.  
  7.         try {
  8.             // readFileSync stops the code execution until the file is ready
  9.             let jsonString = fs.readFileSync(fileOpen, 'utf8');
  10.             let jsObject = JSON.parse(jsonString);
  11.  
  12.             // Store it where the rest of the game can see it
  13.             this._jsonData = jsObject;
  14.             console.log("Data Loaded Successfully:", this._jsonData);
  15.            
  16.             return jsObject;
  17.         } catch (err) {
  18.             console.error("Failed to load JSON:", err);
  19.             return null
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment