JSON content

You can access JSON data from either a post parameter or from the HTTP request content.

You access JSON content from a post parameter by calling request.postParms.<parameter name>.getAsJsonContent().

You access JSON content from the HTTP request by calling request.getAsJsonContent().

Calling either of the methods returns an object of type JsonNode. With a JsonNode object, you can easily iterate over the properties by calling getIterator() with an XPath-like expression.

An example using a JsonNode object with the following value.
{
    records: [
        {
            name: ‘Test Record 1’,
            description: ‘Test Record 1 Description’
        }, 
        {
            name: ‘Test Record 1’,
            description: ‘Test Record 1 Description’
        }]
}
To iterate through the JSON, you can do the following.
var jsonContent = request.getAsJsonContent();
//Get the table name from a URL parameter
var tableName = request.urlParams.tableName;

// This outer loop iterates over all elements in the records array
for (var jsonNodeIter = jsonContent.getIterator(’/records’); jsonNodeIter.hasNext(); ) {
    var jsonNode = jsonNodeIter.next();
    // This inner loop iterates over all child elements in an object in the records array
    for (var propertyIter = jsonNode.iterator(); propertyIter.hasNext(); ) {
        var property = propertyIter.next();
        var propertyName = property.getName();
        
        //The valueFor method replaces the value of the ‘current’ element with an encrypted 
        //value if the field in the table provided as arguments is marked as encrypted. Otherwise, 
        //it leaves the value as-is.
        property.valueFor(tableName, propertyName);

    }
}