@cleverapps/json-extra
v2.1.0
Published
Adds support for importing external jsons and referencing objects inside a json
Downloads
232
Keywords
Readme
Installation
npm i @cleverapps/json-extra
Usage
Inline
const { inlineJSON } = require("@cleverapps/json-extra");
const json = await inlineJSON("/path/to/file.json");
Inline and select env
const { inlineJSON } = require("@cleverapps/json-extra");
const json = await inlineJSON("/path/to/file.json", {
env: "release"
});
Select env only
const { selectEnv } = require("@cleverapps/json-extra");
const json = await selectEnv("/path/to/file.json", {
env: "release"
});
Syntax (throws Error on recurrent includes)
Importing another JSON file
{
"@require": ["other.json", "other2.json"],
"foo": "one",
"aaa": {
"ddd": "ccc"
},
"keep": 1,
"arr": [
3,
4
],
"inner": "@other2.json"
}
other.json
{
"foo": "bar",
"aaa": {
"bbb": "ccc"
},
"keepOrder": 2,
"arr": [
1,
2
]
}
other2.json
{
"other2": "test"
}
Result
{
"foo": "bar",
"aaa": {
"ddd": "ccc",
"bbb": "ccc"
},
"keep": 1,
"arr": [
3,
4,
1,
2
],
"inner": {
"other2": "test"
},
"keepOrder": 2,
"other2": "test"
}