Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
easily create dsl's from json by evaluating json keys and values, json decode on steroids
Generate your own minilanguages fast using json as a startingpoint. No parsetrees, no lexical analyzers, just plain json.
$ npm install json-dsl
in your code
jdsl = require('json-dsl').parse
output = jdsl( yourjson )
By default nested json is converted into xml
{
"div": {
"div": {
"div": "foo"
}
}
}
gets converted into
<div><div><div>foo</div></div></div>
lets evaluate the keys in a different way:
jsondsl = require('json-dsl')
jsondsl.parseKey = function(k) {
return k + "[%s]";
};
output = jdsl( yourjson )
output:
div[div[div[foo]]]
lets take the previous example and lets add parseValue
data = { foo: "bar" }
jsondsl.parseValue = function(v,data) {
return data[v]
}
output = jdsl( yourjson, data )
output:
div[div[div[bar]]]
NOTE: the dsl below is a stripped down version of the brown template engine, a hyperminimalistic template dsl which borrows from emmet and mustache.
setup dsl:
var jdsl = require('json-dsl');
var zen = require('zen-coding');
jdsl.parseKey = function(k) {
return zen(k + '>{%s}');
};
jdsl.parseValue = function(v, data) {
return data[v];
};
lets test it:
var json = {
'div#foo.flop>fieldset>div>ul': {
'li.one>a[href="/"]': 'one',
'li.two>a[href="/"]': 'two'
}
};
var data = {
'one': 'hello',
'two': 'world'
};
console.log(JSON.stringify(json, null, 2));
console.log(jdsl.parse(json, data));
outputs:
<div id="foo" class="flop"><fieldset><div><ul><li class="one"><a href="/">hello</a></li><li class="two"><a href="/">world</a></li></ul></div></fieldset></div>
FAQs
easily create dsl's from json by evaluating json keys and values, json decode on steroids
We found that json-dsl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.