@cleverapps/json-extra
v1.1.2
Published
Adds support for importing external jsons and referencing objects inside a json
Downloads
14
Readme
Installation
npm i @cleverapps/json-extra
Usage
const readJSON = require("@cleverapps/json-extra");
const json = readJSON("/path/to/file.json");
Syntax
Importing another JSON file
{
"@require": "@other.json",
"inner": "@other.json"
}
other.json
{
"foo": "bar"
}
Result
{
"foo": "bar",
"inner": {
"foo": "bar"
}
}
Referencing another object inside JSON
{
"@obj": {
"foo": "bar"
},
"@require": "@obj",
"inner": "@obj"
}
Result
{
"foo": "bar",
"inner": {
"foo": "bar"
}
}
Concatenating arrays
{
"@arr": [
"item1",
"item2",
"item3"
],
"foo": [
"@concat@arr",
"item4",
"item5"
]
}
Result
{
"foo": [
"item1",
"item2",
"item3",
"item4",
"item5"
]
}
String interpolation
const json = readJSON("/path/to/file.json", {
vars: {
env: "release"
}
});
{
"@%{env}": {
"foo": "bar"
},
"obj": "@%{env}"
}
Result
{
"obj": {
"foo": "bar"
}
}