@lorenzmueksch/json-change
v1.1.2
Published
JSON Change
Downloads
3
Readme
Json Change
Description
Json Change is a JavaScript Module to replace Placeholders in an JSON Array or Object with Arguments, which can be defined.
Getting Started
npm install --save @lorenzmueksch/json-change
Insert this line in you app.js
:
const change = require('@lorenzmueksch/json-change');
Usage
change(options);
The Properties of the options are:
- args: The values which will be put in the json
- json: The Json Object or Array you want to change
- fileUri: You can also enter a file Uri if you want to let json-change read the JSON file
The Arguments can be set like this:
[{
"<name of the key>": "<value, which will be injected>"
}]
Define the placeholders in the JSON like this:
${<Name of the key, which will be replaced>}
For Example:
The JSON looks like this:
changeJSON = [
{ msg: "Hello ${username}"},
{ age: "Your Age is ${age}"
];
With Object
The Function to replace the placeholders with your arguments is:
change({ json: changeJSON, args: [{ username: 'LorenzMueksch' }, { age: '18' }]});
The Function will return
[
{ msg: "Hello LorenzMueksch" },
{ age: "Your Age is 18" }
]
With File
This Option will return a JSON Object. It will not write the changes to a file
So if you want to let json-change read your file you can simply set the fileUri in the options Object:
change({ fileUri: 'path to your file', args: [{ username: 'LorenzMueksch' }, { age: '18' }] });
Contact
Lorenz Müksch [email protected]