Reputation: 217
I am unable to parse my 2 json files for some reason. I get a unexpected token at position 0 for the first file and around position 500 for the second file.Below are the two files
file 1:
{"user0":{"username":"user0","password":"user0","gameHistory":[0], "friends":[], "isPublic":true, "profilePic":"https://i.gyazo.com/54ddd66424b6efe51e8acc1d6af67a8c.png"},
"user1":{"username":"user1","password":"user1","gameHistory":[1], "friends":[], "isPublic":true, "profilePic":""},
"user2":{"username":"user2","password":"user2","gameHistory":[2], "friends":[], "isPublic":true, "profilePic":""},
"user3":{"username":"user3","password":"user3","gameHistory":[3], "friends":[], "isPublic":true, "profilePic":""}}
2nd file:
{"0":{"id":"0","mode":"2players","creator":"user0"},
"1":{"id":"1","mode":"2players","creator":"user0"},
"2":{"id":"2","mode":"2players","creator":"user0"},
"3":{"id":"3","mode":"2players","creator":"user0"}}
I am calling these two files through a javascript file using
let games = require("./games.json"); //load initial games
let users = require("./users.json"); //load initial users
Upvotes: 0
Views: 100
Reputation: 3302
You can read it by fs.
"use strict";
const fs = require("fs");
let rawdata = fs.readFileSync("./games.json");
let games = JSON.parse(rawdata);
console.log(games);
Upvotes: 1