---
sourceDocument: Brazil Platform security
sourceDocumentLink: https://www.servicenow.com/docs/r/platform-security

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil Platform security

ft:clusterId :

    - psec

bundleId :

    - psec

workflow :

    - Platform


---

# JSON APIs

# JSON APIs {#ariaid-title1}

Release version: Brazil  
Updated November 19, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of JSON APIs

JSON APIs in ServiceNow allow you to work with JSON payloads by using methods on the request object or ParameterValue properties.
These APIs enable you to iterate through JSON nodes, map JSON elements to specific table fields, and apply encryption rules dynamically based on your instance's encryption configurations.
Show full answer Show less  

## Using JSON APIs for Encryption Rules

To write encryption rules with JSON APIs, you typically:

* Call **getAsJsonContent()** on the request object to get a JsonNode iterable object.
* Use **getIterator()** or **iterator()** on a JsonNode to obtain a JsonNodeIterator for traversing JSON nodes.
* Check for additional nodes using **hasNext()** and retrieve them using **next()**.
* Map JSON elements to table fields by calling **valueFor(String tableName, String fieldName)** on JSON elements, which triggers the proxy to determine if encryption is needed for that field.

The **getName()** method lets you identify JSON element names to decide if and how to map them.

## Examples of Mapping JSON to Table Fields

* **Known table-field mapping:** Iterate over JSON nodes at a given XPath (e.g., `/data/records/description`) and call `valueFor()` to encrypt and map values to a specific field (e.g., `incident.shortdescription`).
* **Unknown table-field mapping:** Dynamically iterate over records and their fields, mapping each JSON node to a table field named after the node. Special cases (e.g., mapping `description` to `shortdescription`) can be handled within the iteration.
* The proxy skips nodes that do not match configured encrypted fields or are not present in the table schema.

## Handling Encoded Queries

When processing JSON containing encoded queries, you can iterate over the JSON payload, identify the query node, and call **encodedQueryFor(tableName)** to apply encryption to values within the query string.

## Key Objects and Methods

* **JsonNode:** Represents JSON content with methods for iteration.
* **JsonNodeIterator:** Obtained via `getIterator()` or `iterator()`, used to traverse JSON nodes sequentially.
* **valueFor(tableName, fieldName):** Maps a JSON element's value to a database table field and triggers encryption if configured.
* **encodedQueryFor(tableName):** Encrypts values within encoded query strings in JSON.

## Practical Benefits

By leveraging JSON APIs, ServiceNow customers can create flexible and dynamic encryption rules that:

* Support complex JSON payloads with nested arrays and objects.
* Encrypt sensitive data fields automatically based on configured encryption policies.
* Handle both known and unknown JSON structures by dynamically mapping JSON elements to table fields.
* Ensure secure handling of encoded query parameters within JSON requests.

This approach enhances data security while maintaining the flexibility needed for integration with varied JSON data formats.  
JSON APIs can be used after calling getAsJsonContent() on either
the request object or a ParameterValue property.
When using JSON APIs to write your encryption rule, you can follow a general format:

1. Call getAsJsonContent() on the request object. This returns an iterable object of the JsonNode underlying class.
2. Call iterator() or getIterator(String xPath) on the JsonNode object. This returns a JsonNodeIterator object that can be used to iterate over nodes in the JSON object.
3. Call the hasNext() method on the JsonNodeIterator object to determine whether another element is available.
4. Call next() on the JsonNodeIterator object to return the next JSON element. You cannot call next() without first calling hasNext().
5. Call valueFor(String tableName, String fieldName) on the JSON element. This method tells the proxy that the value for this element maps to the specified field in the specified table. The proxy then checks whether the field must be encrypted.  
   Note:  
   To determine if you want to call valueFor(String tableName, String fieldName) on a JSON element, you can use the getName() method to return the name of the element.
{#json-overview__ol_qfz_kmt_dz}

## Mapping to a known table-field on the instance {#json-overview__section_hhq_fsd_yz}

In this example, the JSON payload is processed on the instance to insert records in
the incident table. The description field populates short_description on the
incident.  

    {
        data: {
            records: [
                {
                    "name": "Test Record 1",
                    "description": "Test Record 1 Description",
                    "tag": "security"
                }, 
                {
                    "name": "Test Record 1",
                    "description": "Test Record 1 Description",
                    "tag": "security"
                }],
            "query": "assigned_to=3D4860165813e63a00d00abd322244b092^category=vulnerability"
        },
        "source": "10.11.13.14"
    }

The following rule can apply:  

    function sampleJsonAction1() {
        var jsonContent = request.getAsJsonContent();
        // This loop iterates over all description elements in the records array
        var jsonNodeIterator = jsonContent.getIterator('/data/records/description');    
        while (jsonNodeIterator.hasNext()) {
            var jsonNode = jsonNodeIterator.next();
            jsonNode.valueFor('incident', 'short_decription');
        }
    }

This action iterates through the description nodes and asks
the proxy server to encrypt the values and insert them into
incident.short_description on the instance.  
Note:  
This rule finds all description nodes within the JSON payload. If there is only one occurrence of a node to encrypt, the rule still uses the xPath and iterator structure. However, it iterates only once in the loop.

## Mapping to an unknown table-field on the instance {#json-overview__json-dynamic}

In this example, the rule iterates over records, but is not
sure what nodes to expect. The only known is that for each object within
records, the nodes match the names of the columns
specified in the table URL parameter.

The rule also specifies that, if the table is incident, then the data in the
description node should be encrypted and stored in the
short_description field on the instance.  

    function sampleJsonAction2() {
        var jsonContent = request.getAsJsonContent();
        var tableName = request.urlParam.table;
        // This first iterator will iterate over all record elements
        var jsonNodeIterator = jsonContent.getIterator('data/records');
        while (jsonNodeIterator.hasNext()) {
                encryptFieldsInRecord(jsonNodeIterator.next());
        }
    }
    function encryptFieldsInRecord(jsonNode) {
        //this time we want to iterate over all nodes
        var fieldIterator = jsonNode.iterator();
        while (fieldIterator.hasNext()) {
                var field = fieldIterator.next();
                var fieldname = childElement.getName();
                if (fieldName == 'description') {
                    field.valueFor(tableName, 'short_description');
                } else {
                    field.valueFor(tableName, fieldName);
                }
        }
    }

In the encryptFieldsInRecord() function, the
valueFor() method is called on a table and a field that are
dynamically assigned based on the request. Even though the table and field names can
change, the rule asks the proxy to check whether the field in the table must be
encrypted based on the encryption configurations defined.

If the field is not configured for encryption, or if the node name does not match a
field in the table, the proxy skips that node. If the node name matches a field
marked for encryption, then the proxy encrypts the value.

## Using an encoded query {#json-overview__section_sbq_msd_yz}

    function sampleJsonAction3() {
        var jsonContent = request.getAsJsonContent();
        var tableName = request.urlParam.table;
        // This first iterator will iterate over all record elements
        var jsonNodeIterator = jsonContent.getIterator('data');
        while (jsonNodeIterator.hasNext()) {
            var jsonNode = jsonNodeIterator.next();
            if (jsonNode.getName() == 'records')
                encryptRecors(jsonNodeIterator.next());
            else if (jsonNode.getName() == 'query')
                jsonNode.encodedQueryFor(tableName);
        }
    }
    function encryptRecords(jsonNode) {
        //we iterate over all fields in the node
        var recordIterator = jsonNode.iterator();
        while (recordIterator.hasNext()) {
            encryptFieldsInRecord(recordIterator.next());
        }
    }
    function encryptFieldsInRecord(jsonNode) {
        //this time we want to iterate over all nodes
        var fieldIterator = jsonNode.iterator();
        while (fieldIterator.hasNext()) {
                var field = fieldIterator.next();
                var fieldname = childElement.getName();
                field.valueFor(tableName, fieldName);
        }
    }

In this example, the rule iterates over data. As it finds
records, it performs the same logic as in the second
example, iterating over fields in each node. When it finds the
query node, it calls encodedQueryFor()
to encrypt values that should be encrypted in the query.
* **[JsonNode](https://www.servicenow.com/docs/E6W5dx1t~eVlMI1ohoDs4A#c_JsonNodeAPI)**   
  A global object that provides methods to iterate over the JSON content.
* **[JsonNodeIterator](https://www.servicenow.com/docs/xRArmDAAzkLpuzhaHFEJ0w#c_JsonNodeIteratorAPI)**   
  You get a JsonNodeIterator object by calling the getIterator() or iterator() methods of the JsonNode class.

