Skip to content

Instantly share code, notes, and snippets.

@jgwill
Last active April 11, 2019 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgwill/49b63ccb5dda6f1f479ddf941aea56e5 to your computer and use it in GitHub Desktop.
Save jgwill/49b63ccb5dda6f1f479ddf941aea56e5 to your computer and use it in GitHub Desktop.
@stcgoal Optimal Management of JSON Files
{
"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"
}
}
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