node-self-referenced-json
Load self referenced json to object
- use $() to add a value reference
- use &() to add a real object reference
- use {{}} (mustache style) to add a reference as part of a string
Example
myTemplate.json
myApp.js
var SRJson = ; var mySettings = SRJson;console;
Option
var SRJSON = ;SRJson;
Option can be
undefined
, all default values will be used.
Syntax
"$()"
returns
propA: propInsideA: 20 propB: 20
"&()"
returns
propA: propInsideA: 20 propB: propInsideA: 20 // if you change the propB.propInsideA, propA.propInsideA will also be changed.
take care while using
&()
with a circular reference, the result could be unexpected.
"{{}}"
same as mustache
returns
propA: 20 propB: "the value is 20"
Details
please check the source file tests.js
for more details.