electron-storage icon indicating copy to clipboard operation
electron-storage copied to clipboard

Not a Valid JSON file when suing get method.

Open alexiusacademia opened this issue 8 years ago • 3 comments

Hi there. I get this error on macOS.

var data = new Object();
    data.name = name;
    data.address = address;

    storage.set('customers.json', data)
    .then(() => {
      console.log('Data saved successfully!')
    })
    .catch((err) => {
      console.log(err);
    });

It writes to the file but then when I use the get function,

var oldData = storage.get('customers.json')
    .then(d => {
      console.log(d);
    })
    .catch(err => {
      console.log(err);
    });

It gives me that the error.

And here is what the console gives:

Error: The file in path /Users/syncster31/Library/Application Support/ASMS/customers.json is not a valid json file at /Users/syncster31/Documents/Programming/Electron/my-app/node_modules/electron-storage/dist/index…:37 at tryToString (fs.js:449) at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:436)

alexiusacademia avatar Oct 16 '17 08:10 alexiusacademia

@alexiusacademia Same error. How did you solved it ? Thks

gregoirepuget avatar Feb 02 '21 09:02 gregoirepuget

Same error on mac

gregoirepuget avatar Feb 02 '21 09:02 gregoirepuget

I didn't. I wrote my own library electron-db.

alexiusacademia avatar Feb 10 '21 21:02 alexiusacademia