Write json file follow json format


#1

Hi guys,
I have a object, ex: var obj = {name: ‘hello’, age: 25}, I want to save the object to json file, I used electron-storage node module to do that, but when I open the json file, they look like : {name: ‘hello’, age: 25}
How to do content of the json file looks like:
{
name: ‘hello’,
age: 25
}


#2

It’s possible (but potentially a waste of space). It’s best to prettify it in your text editor/IDE when you open it, rather than saving it prettified.

Either way, I’m not sure whether it’s possible from electron-storage, but the built-in JSON object has this function: JSON.stringify(value[, replacer[, space]]), used like JSON.stringify(objectToStringify,null,numberOfSpacesToUseAsWhiteSpace)