WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

JSON

It is very simple to work with JSON in javascript, Rhino provides a native JSON object to parse and serialize JSON.

Serialize

This script...

var a={ x : 1, y : 2 };
context.createResponseFrom(JSON.stringify(a));

...will return...

{"x":1,"y":2}

Parse

Assuming you have a resource with identifier res:/data.json like...

{"x":1,"y":2}

The following code...

var s=context.source("res:/data.json", java.lang.String);   
var a=JSON.parse(s);

context.createResponseFrom(a.x);

...will return...

1.0

JSON REST Service

Of course the most likely source of JSON is a REST service. If you import urn:org:netkernel:client:http to your space you can do this...

var s=context.source("http://somehost/rest/path/json-service", java.lang.String);   
var rep=JSON.parse(s);

//... do whatever with rep from the service...