---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# JSONStreamingAPI - Scoped

# JSONStreamingAPI - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 19 minutes to read

Build a large streaming JSON payload to use in a REST or SOAP request to send bulk data to a third-party API. You can also create the payload as a JSON string for a non-streaming option.
Use these methods in the Workflow Studio script step with the `sn_ih` namespace identifier. For example, you can use this API to create a JSON payload in the Workflow Studio Script step and pass the returned value to the REST step to send the request to a third-party service. For more information, see the Workflow Studio [Script
step](https://www.servicenow.com/docs/access?context=javascript-step-action-designer&version=xanadu&pubname=xanadu-build-workflows&ft:locale=en-US).

You can only use this API within the Workflow Studio environment.

To use this class, you must call the build() method in the
JSONStreamingBuilder class to return a JSONStreamingAPI object. See
[JSONStreamingBuilder - Scoped](https://servicenow-prod.fluidtopics.net/DpPIUGA0QxuHkDqE_tIPlA#JSONStreamingBuilderScopedAPI "Create a builder object used to build a large streaming JSON payload to use in a REST or SOAP request to send bulk data to a third-party API. You can also create the payload as a JSON string for a non-streaming option.").

## API call order {#JSONStreamingAPIScopedAPI__section_owy_pd5_hlb}

Generate JSON payloads using these APIs in the following order:  

JSONStreamingBuilder: Creates a builder object
:   Use these methods in the following order to create a builder object:  
    1. JSONStreamingBuilder(): Instantiates the JSONStreamingBuilder object.{#JSONStreamingAPIScopedAPI__json-api-constructor}
    2. withAttachment(): Optional. Creates the JSON object as a streaming attachment and stores it in the Streaming Attachments \[streaming_attachment\] table. If you do not call this method, the API creates the payload as a JSON string.{#JSONStreamingAPIScopedAPI__with-attachments}
    3. expiresAt(): Optional. Sets a time when the attachment expires. Must also call the withAttachment() method.{#JSONStreamingAPIScopedAPI__expires-at}
    4. build(): Returns a JSONStreamingAPI object.{#JSONStreamingAPIScopedAPI__build}
    {#JSONStreamingAPIScopedAPI__ol_obn_dd5_hlb}

JSONStreamingAPI: Builds the JSON payload
:   Use these methods in the following order to create the JSON payload:  
    1. startObject(): Creates the parent JSON object.{#JSONStreamingAPIScopedAPI__start-object}
    2. Methods to generate the JSON key-value pairs, such as writeFieldName(), writeString(), and writeNumberField().
    3. endObject(): Closes the parent JSON object.{#JSONStreamingAPIScopedAPI__end-object}
    4. getJSONString() or getAttachmentId(): Returns the JSON string or attachment ID that you created.
    5. close(): Closes the JSONStreamingAPI object.{#JSONStreamingAPIScopedAPI__close}
    {#JSONStreamingAPIScopedAPI__ol_yzk_qgn_hlb}

## Size limits {#JSONStreamingAPIScopedAPI__section_qkj_sd5_hlb}

Payloads generated through this API cannot exceed these size limits:  
* Attachments: 200 MB
* Strings: 5 MB
{#JSONStreamingAPIScopedAPI__ul_syy_lsw_3lb}

## Example {#JSONStreamingAPIScopedAPI__section_nzz_rd5_hlb}

This example create a JSON object and stores it in the Attachment \[sys_attachment\] table
with a defined expiration date. You can use this option to create payloads under 5 MB.  

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

Alternatively, this example uses the API in the Script step and creates the payload as a
JSON string. You can use this option to create payloads under 5 MB.  

    (function execute(inputs, outputs) {

      var builder = new sn_ih.JSONStreamingBuilder().build();
      
      builder.startObject()
        .enablePrettyPrint()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
          .writeStringField("streetAddress", "21 2nd Street")
          .writeStringField("city", "Santa Clara")
          .writeStringField("state", "CA")
          .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
          .startObject()
            .writeFieldName("type")
            .writeString("home")
            .writeFieldName("number")
            .writeString("212 555-1234")
          .endObject()
          .startObject()
            .writeFieldName("type")
            .writeString("fax")
            .writeFieldName("number")
            .writeString("646 555-4567")
          .endObject()
        .endArray()
        .endObject()

      outputs.payload = builder.getJSONString();
      
    })(inputs, outputs);

Output:  

    {
    "firstName" : "John",
    "lastName" : "Smith",
    "age" : 25,
    "address" : {
      "streetAddress" : "21 2nd Street",
      "city" : "Santa Clara",
      "state" : "CA",
      "postalCode" : "11111"
    },
    "phoneNumber" : [ {
      "type" : "home",
      "number" : "212 555-1234"
    }, {
      "type" : "fax",
      "number" : "646 555-4567"
    } ]
    }

## JSONStreamingAPI - close() {#ariaid-title2}

Closes the JSONStreamingAPI object. Must call this method to close
the stream after building a JSON object.
{#JSA-close__table_izv_lb5_hlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#JSA-close__table_izv_lb5_hlb} {#JSA-close__table_jzv_lb5_hlb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 2. Returns]

{#JSA-close__table_jzv_lb5_hlb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - disablePrettyPrint() {#ariaid-title3}

Ends pretty print JSON formatting.
Before calling this method, you must first call enablePrettyPrint() to
add JSON formatting to a specific section.
{#JSA-disablePrettyPrint__table_ebl_hh2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#JSA-disablePrettyPrint__table_ebl_hh2_1lb} {#JSA-disablePrettyPrint__table_fbl_hh2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 4. Returns]

{#JSA-disablePrettyPrint__table_fbl_hh2_1lb}  
This example adds pretty print formatting to the `address` object.

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")  
        .writeNumberField("age","25")
        .enablePrettyPrint()
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .disablePrettyPrint()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

Output:

    {"firstName":"John","lastName":"Smith","age":25,
    "address" : {
      "streetAddress" : "21 2nd Street",
      "city" : "Santa Clara",
      "state" : "CA",
      "postalCode" : "11111"
    },"phoneNumber":[{"type":"home","number":"212 555-1234"},{"type":"fax","number":"646 555-4567"}]}

## JSONStreamingAPI - enablePrettyPrint() {#ariaid-title4}

Adds pretty print formatting to a JSON object, or a section of a JSON object.
To disable pretty print formatting in a JSON object section, use the
disablePrettyPrint() method.
{#JSA-enablePrettyPrint__table_h5h_gh2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 5. Parameters]

{#JSA-enablePrettyPrint__table_h5h_gh2_1lb} {#JSA-enablePrettyPrint__table_fbl_hh2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 6. Returns]

{#JSA-enablePrettyPrint__table_fbl_hh2_1lb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.enablePrettyPrint()
        .startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

Output:

    {
    "firstName" : "John",
    "lastName" : "Smith",
    "age" : 25,
    "address" : {
      "streetAddress" : "21 2nd Street",
      "city" : "Santa Clara",
      "state" : "CA",
      "postalCode" : "11111"
    },
    "phoneNumber" : [ {
      "type" : "home",
      "number" : "212 555-1234"
    }, {
      "type" : "fax",
      "number" : "646 555-4567"
    } ]
    }

## JSONStreamingAPI - endArray() {#ariaid-title5}

Closes an array within the parent JSON object.
Call the startArray() method first to open the array.
{#JSA-endArray__table_p1h_kf2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#JSA-endArray__table_p1h_kf2_1lb} {#JSA-endArray__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 8. Returns]

{#JSA-endArray__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - endObject() {#ariaid-title6}

Closes an object within the parent JSON object.
Call the startObject() method first to open the object.
{#JSA-endObject__table_rzg_gf2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#JSA-endObject__table_rzg_gf2_1lb} {#JSA-endObject__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 10. Returns]

{#JSA-endObject__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - getAttachmentId() {#ariaid-title7}

Returns the sys_id of the attachment record in the Streaming Attachments
\[streaming_attachment\] table that contains the JSON payload.
You must call the withAttachment() method in the
JSONStreamingBuilder class to save the JSON payload as an attachment
before calling this method. See [JSONStreamingBuilder - Scoped](https://servicenow-prod.fluidtopics.net/DpPIUGA0QxuHkDqE_tIPlA#JSONStreamingBuilderScopedAPI "Create a builder object used to build a large streaming JSON payload to use in a REST or SOAP request to send bulk data to a third-party API. You can also create the payload as a JSON string for a non-streaming option.").
{#JSA-getAttachmentId__table_j2q_p25_hlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#JSA-getAttachmentId__table_j2q_p25_hlb} {#JSA-getAttachmentId__table_k2q_p25_hlb__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the attachment record in the Streaming Attachments \[streaming_attachment\] table that contains the JSON payload. |
[Table 12. Returns]

{#JSA-getAttachmentId__table_k2q_p25_hlb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - getJSONString() {#ariaid-title8}

Returns the JSON object as a string.
To return the JSON object as a string, do not call the withAttachment()
method in the JSONStreamingBuilder class. See [JSONStreamingBuilder - Scoped](https://servicenow-prod.fluidtopics.net/DpPIUGA0QxuHkDqE_tIPlA#JSONStreamingBuilderScopedAPI "Create a builder object used to build a large streaming JSON payload to use in a REST or SOAP request to send bulk data to a third-party API. You can also create the payload as a JSON string for a non-streaming option.").
{#JSA-getJSONString__table_bth_r25_hlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#JSA-getJSONString__table_bth_r25_hlb} {#JSA-getJSONString__table_cth_r25_hlb__entry__2}

| Type | Description |
|-|-|
| String | Contains the JSON object built using the JSONStreamingAPI. |
[Table 14. Returns]

{#JSA-getJSONString__table_cth_r25_hlb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

Output:

    {
    "firstName" : "John",
    "lastName" : "Smith",
    "age" : 25,
    "address" : {
      "streetAddress" : "21 2nd Street",
      "city" : "Santa Clara",
      "state" : "CA",
      "postalCode" : "11111"
    },
    "phoneNumber" : [ {
      "type" : "home",
      "number" : "212 555-1234"
    }, {
      "type" : "fax",
      "number" : "646 555-4567"
    } ]
    }

## JSONStreamingAPI - startArray() {#ariaid-title9}

Opens an array within the parent JSON object.
Include the endArray() method to close the array.
{#JSA-startArray__table_ljl_3f2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 15. Parameters]

{#JSA-startArray__table_ljl_3f2_1lb} {#JSA-startArray__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 16. Returns]

{#JSA-startArray__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - startArrayField(String fieldName) {#ariaid-title10}

Creates an array within the parent JSON object.
Surround this method with the startArray() and
endArray() methods to open and close the array.
{#JSA-startArrayField_S__table_fmw_wg2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | The name of the array. |
[Table 17. Parameters]

{#JSA-startArrayField_S__table_fmw_wg2_1lb} {#JSA-startArrayField_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 18. Returns]

{#JSA-startArrayField_S__table_q1h_kf2_1lb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .startArrayField("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - startObject() {#ariaid-title11}

Opens an object within the parent JSON object.
Requires the endObject() method to close the object.
{#JSA-startObject__table_fmc_2f2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 19. Parameters]

{#JSA-startObject__table_fmc_2f2_1lb} {#JSA-startObject__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 20. Returns]

{#JSA-startObject__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeBoolean(Boolean state) {#ariaid-title12}

Adds a Boolean value to the parent JSON object.
{#JSA-writeBoolean_B__table_abc_4f2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| state | Boolean | The boolean value to add to the parent JSON object. Valid values: * true * false {#JSA-writeBoolean_B__ul_js4_hzs_1mb} |
[Table 21. Parameters]

{#JSA-writeBoolean_B__table_abc_4f2_1lb} {#JSA-writeBoolean_B__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 22. Returns]

{#JSA-writeBoolean_B__table_q1h_kf2_1lb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeFieldName("activeUser")
        .writeBoolean(true)
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeBooleanField(String fieldName, Boolean value) {#ariaid-title13}

Adds a Boolean field and value to the parent JSON object.
{#JSA-writeBooleanField_S_B__table_qtm_dh2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | The name of the field to add to the parent JSON object. |
| value | Boolean | The boolean value to add to the parent JSON object. Valid values: * true * false {#JSA-writeBooleanField_S_B__ul_js4_hzs_1mb} |
[Table 23. Parameters]

{#JSA-writeBooleanField_S_B__table_qtm_dh2_1lb} {#JSA-writeBooleanField_S_B__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 24. Returns]

{#JSA-writeBooleanField_S_B__table_q1h_kf2_1lb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeBooleanField("activeUser", true)
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")  
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeFieldName(String name) {#ariaid-title14}

Adds a field name to the parent JSON object.
{#JSA-writeFieldName_S__table_bsf_mf2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Field name to add to the parent JSON object. |
[Table 25. Parameters]

{#JSA-writeFieldName_S__table_bsf_mf2_1lb} {#JSA-writeFieldName_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 26. Returns]

{#JSA-writeFieldName_S__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeNull() {#ariaid-title15}

Adds a null value to the parent JSON object.
{#JSA-writeNull__table_bdp_wf2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 27. Parameters]

{#JSA-writeNull__table_bdp_wf2_1lb} {#JSA-writeNull__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 28. Returns]

{#JSA-writeNull__table_q1h_kf2_1lb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeFieldName("activeUser")
        .writeNull()
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeNullField(String fieldName) {#ariaid-title16}

Adds a field with a null value to the parent JSON object.
{#JSA-writeNullField_S__table_ifs_nh2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | The name of the null field. |
[Table 29. Parameters]

{#JSA-writeNullField_S__table_ifs_nh2_1lb} {#JSA-writeNullField_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 30. Returns]

{#JSA-writeNullField_S__table_q1h_kf2_1lb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeNullField("activeUser")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()  
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeNumberField(String fieldName, String encodedValue) {#ariaid-title17}

Adds a number field and value to the parent JSON object.
{#JSA-writeNumberField_S_S__table_bqd_rf2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | The name of the number field. |
| encodedValue | String | The value of the number field. |
[Table 31. Parameters]

{#JSA-writeNumberField_S_S__table_bqd_rf2_1lb} {#JSA-writeNumberField_S_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 32. Returns]

{#JSA-writeNumberField_S_S__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeRaw(String text) {#ariaid-title18}

Adds a raw value to the parent JSON object.
{#JSA-writeRaw_S__table_pkv_5f2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| text | String | Raw text to add to the parent JSON object. |
[Table 33. Parameters]

{#JSA-writeRaw_S__table_pkv_5f2_1lb} {#JSA-writeRaw_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 34. Returns]

{#JSA-writeRaw_S__table_q1h_kf2_1lb}  

    try {
      var builder = new sn_ih.JSONStreamingBuilder().build();

      builder.startObject()
        .writeFieldName("firstName")
        .writeString("John")
        .writeFieldName("lastName")
        .writeString("Smith")
        .writeFieldName("filePath")
        .writeRaw("C:\Users\profile\aboutme.html")
        .writeNumberField("age","25")
        .writeFieldName("address")
        .startObject()
        .writeStringField("streetAddress", "21 2nd Street")
        .writeStringField("city", "Santa Clara")
        .writeStringField("state", "CA")
        .writeStringField("postalCode", "11111")
        .endObject()
        .writeFieldName("phoneNumber")
        .startArray()
        .startObject()
        .writeFieldName("type")
        .writeString("home")
        .writeFieldName("number")
        .writeString("212 555-1234")
        .endObject()
        .startObject()
        .writeFieldName("type")
        .writeString("fax")
        .writeFieldName("number")
        .writeString("646 555-4567")
        .endObject()
        .endArray()
        .endObject()

      gs.log(builder.getJSONString());
    } 

    catch (err) {
      gs.log("Exception: " + err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeString(String text) {#ariaid-title19}

Adds a string value to the parent JSON object.
{#JSA-writeString_S__table_arf_tf2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| text | String | The string value to add to the parent JSON object. |
[Table 35. Parameters]

{#JSA-writeString_S__table_arf_tf2_1lb} {#JSA-writeString_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 36. Returns]

{#JSA-writeString_S__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }

## JSONStreamingAPI - writeStringField(String fieldName, String value) {#ariaid-title20}

Adds a string field and value to the parent JSON object.
{#JSA-writeStringField_S_S__table_qtm_dh2_1lb__entry__3}

| Name | Type | Description |
|-|-|-|
| fieldName | String | The name of the field to add to the parent JSON object. |
| value | String | The value of the field. |
[Table 37. Parameters]

{#JSA-writeStringField_S_S__table_qtm_dh2_1lb} {#JSA-writeStringField_S_S__table_q1h_kf2_1lb__entry__2}

| Type | Description |
|-|-|
| JSONStreamingAPI | Streaming JSON object used to construct the payload. |
[Table 38. Returns]

{#JSA-writeStringField_S_S__table_q1h_kf2_1lb}  
This example shows how to create a JSON object and store it in the Attachment
\[sys_attachment\] table with a defined expiration date.

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.JSONStreamingBuilder()
        .withAttachment() // Creates the JSON object in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the JSONStreamingAPI object. 

      builder.startObject()  // Begins generating the JSON object.
    	.writeFieldName("firstName")  // Adds a "firstName" field 
    	.writeString("John")          // Writes the value of the "firstName" field
    	.writeFieldName("lastName")
    	.writeString("Smith")
    	.writeNumberField("age","25") // Write a number field named "age" with value "25"
    	.writeFieldName("address")
    	.startObject()                // Start a new object nested under the parent object
    		.writeStringField("streetAddress", "21 2nd Street")
    		.writeStringField("city", "Santa Clara")
    		.writeStringField("state", "CA")
    		.writeStringField("postalCode", "11111")
    	.endObject()
    	.writeFieldName("phoneNumber")
    	.startArray()                    // Start an array 
    		.startObject()               // Add the first object to the array 
    			.writeFieldName("type")
    			.writeString("home")
    			.writeFieldName("number")
    			.writeString("212 555-1234")
    		.endObject()
    		.startObject()               // Add another object to the array 
    			.writeFieldName("type")
    			.writeString("fax")
    			.writeFieldName("number")
    			.writeString("646 555-4567")
    		.endObject()
    	.endArray()
    	.endObject()

      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } 

    catch (err) {
      gs.log(err);
    } 

    finally {
      builder.close();
    }


