
DefiantJS provides the ability for you to build smart templates applicable on JSON structures, based upon proven & standardized technologies such as XSLT and XPath.
DefiantJS also extends the global object JSON with the method "search", which enables searches on JSON structures with XPath expressions and returns matches as an array-like object.
For detailed information, please visit defiantjs.com and try out the XPath Evaluator or...
:point_right:
Chat with Defiant.js users
Example usage
- Snapshots - very large JSON
var data = {
};
Defiant.getSnapshot(data, function(snapshot) {
found = JSON.search(snapshot, '//item');
});
var data = {
};
found = JSON.search(data, '//item');
var snapshot = Defiant.getSnapshot(data);
found = JSON.search(snapshot, '//item');
var data = [
{ "x": 2, "y": 0 },
{ "x": 3, "y": 1 },
{ "x": 4, "y": 1 },
{ "x": 2, "y": 1 }
],
res = JSON.search( data, '//*[ y > 0 ]' );
console.log( res );
<script type="defiant/xsl-template">
<xsl:template name="books_template">
<xsl:for-each select="//movie">
<xsl:value-of select="title"/><br/>
</xsl:for-each>
</xsl:template>
</script>
<script type="text/javascript">
var data = {
"movie": [{"title": "The Usual Suspects"},
{"title": "Pulp Fiction"},
{"title": "Independence Day"}]
},
htm = Defiant.render('books_template', data);
console.log(htm);
</script>
Update highlights
-
v1.2.6
As of this version, snapshots can be created with web workers - consequently the UI thread is not blocked when creating snapshots of large JSON structures.
-
v1.2.0
As of version 1.2.0, the snapshot feature was added. Using this feature, the performance of the search is increased by more than 100 times. Use 'snapshot search' when you are certain that the JSON structure hasn't been changed. If the structure changes, create a new snapshot and always make searches on the latest snapshot. The example below shows how it can be used.
Changelog