Last active
April 11, 2019 11:53
-
-
Save jgwill/49b63ccb5dda6f1f479ddf941aea56e5 to your computer and use it in GitHub Desktop.
@stcgoal Optimal Management of JSON Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "transapp", | |
"version": "0.0.1", | |
"description": "Master the Translate API to create. string Hello world is adde to each lang located in the i18n directory using the translator", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "Guillaume Isabelle", | |
"license": "ISC", | |
"dependencies": { | |
"@exponent/json-file": "^5.3.0", | |
"@google-cloud/translate": "^3.0.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var JsonFile = require('@exponent/json-file'); | |
//@exponent/json-file | |
//@stcgoal Optimal management of JSON file | |
//@urir https://www.npmjs.com/package/@exponent/json-file | |
//reads the JSON file | |
var file = new JsonFile('dummy.json', {cantReadFileDefault: {}}); | |
//Read the File | |
file.readAsync() | |
.then((obj)=> | |
{ | |
//Adding new keys and value to the json file | |
obj.mynewkey = "something"; | |
obj.mynewroot = new Object(); | |
obj.mynewroot.myval = "a new subchild"; | |
//@STCAction Show up each keys | |
var keys = Object.keys(obj); | |
for (var i = 0; i < keys.length; i++) { | |
var v = obj[keys[i]]; | |
console.log(v); | |
} | |
//@STCgoal Writes the new JSON file | |
file.writeAsync(obj); | |
}) | |
.catch((err)=>{ | |
console.log(err); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment