I used the following instead of the standard ant script/javascript tag. This allows JSON.stringify to be called.
<sequential>
<script language="javascript" manager="bsf">
<classpath>
</classpath><![CDATA[
var shell = org.mozilla.javascript.tools.shell.Main;
var args = ["-e","var a='STRING';"];
shell.exec(args);
var shellGlobal = shell.global;
@{text}
]]></script>
</sequential>
</macrodef>
...
<rhinoscript><![CDATA[
JSON.stringify(obj);
]]</rhinoscript>