Skip to content
Ruslan Konev edited this page Sep 16, 2016 · 2 revisions

Just-JSON wiki

Usage

Methods

Upgrade structure of json-files from 0.1.* to 0.2

const fs = require('fs');

// Upgrade structure of json-files from 0.1.* to 0.2
let files = fs.readdirSync('./stores/db', 'utf8');
if (files && files.length) {
    files.forEach( item => {
        let file = './stores/db/' + item;
        console.log(`process [${file}] file`);
        let data = require(file);
        let newData = {
            "updated_at": Date.now(),
            "entries": data
        }
        fs.writeFileSync(file, JSON.stringify(newData), 'utf8')
    })
}
Clone this wiki locally