James Wiltshire and his team at ATG have created and released a JSP tag library that is used to render JSON data from within JSP code. They use JSON as our data format of choice for
all AJAX applications being written at ATG, and they use this library
extensively to render the JSON.
This allows JSON data rendering JSPs to sit alongside existing HTML
rendering JSPs as part of the view layer when using any of the various
Java MVC frameworks (Struts, WebWork, Spring MVC, et al).
The libray has been released under an Apache License v2.0 on SourceForge.
Example
JSP:
<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>
<json :data>
<json :property name="aString" value="foo"/>
</json><json :property name="anotherString">
Foo
</json>
<json :property name="bool1" value="${true}"/>
<json :property name="numeric1" value="${1+2}"/>
<json :object name="anObject">
<json :property name="fee" value="fi"/>
<json :property name="fo" value="fum"/>
</json>
<json :array name="anArray" items="${daysOfWeek}"/>
becomes:
JAVASCRIPT:
-
-
{
-
"aString": "foo",
-
"anotherString": "Foo",
-
"bool1": true,
-
"numeric1": 3,
-
"anObject": {
-
"fee": "fi",
-
"fo": "fum"
-
},
-
"anArray": ["Mon","Tue","Wed","Thur","Fri","Sat","Sun"]
-
}
-