I would like to use some expression language in JSON objects. Say I have a "template", for example:
jsonTemplate = {
title:"Title: '#{title}',
header: "Created by
}
and actual data:
data = {
title: "Some title",
content:"bla...",
meta: {createdAt:new Date(), author:"me"}
}
I would like to do something similar to
parser.render(jsonTemplate, data);
for return
{
title:"Title: 'Some title'",
header: "Created by me at 2012-05-10 10:00:00"
}
All template engines focus on html generation, but the result of the render step should be a json object.
Is there any engine that allows this?
If not, I would create the json object myself and apply the existing engine to individual attributes. Would you recommend an engine for this?
Ideally, this should be available as node.js module or common.js.
source
share