JSONStreamingAPI - Scoped
-
- UpdatedJan 30, 2025
- 15 minutes to read
- Yokohama
- API reference
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.
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.
API call order
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:
- JSONStreamingBuilder(): Instantiates the JSONStreamingBuilder object.
- 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.
- expiresAt(): Optional. Sets a time when the attachment expires. Must also call the withAttachment() method.
- build(): Returns a JSONStreamingAPI object.
- JSONStreamingAPI: Builds the JSON payload
- Use these methods in the following order to create the JSON payload:
- startObject(): Creates the parent JSON object.
- Methods to generate the JSON key-value pairs, such as writeFieldName(), writeString(), and writeNumberField().
- endObject(): Closes the parent JSON object.
- getJSONString() or getAttachmentId(): Returns the JSON string or attachment ID that you created.
- close(): Closes the JSONStreamingAPI object.
Size limits
Payloads generated through this API cannot exceed these size limits:
- Attachments: 200 MB
- Strings: 5 MB
Example
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.
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.
Output:
JSONStreamingAPI - close()
Closes the JSONStreamingAPI object. Must call this method to close the stream after building a JSON object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
void |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - disablePrettyPrint()
Ends pretty print JSON formatting.
Before calling this method, you must first call enablePrettyPrint() to add JSON formatting to a specific section.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example adds pretty print formatting to the address
object.
JSONStreamingAPI - enablePrettyPrint()
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.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
JSONStreamingAPI - endArray()
Closes an array within the parent JSON object.
Call the startArray() method first to open the array.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - endObject()
Closes an object within the parent JSON object.
Call the startObject() method first to open the object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - getAttachmentId()
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.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Sys_id of the attachment record in the Streaming Attachments [streaming_attachment] table that contains the JSON payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - getJSONString()
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.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Contains the JSON object built using the JSONStreamingAPI. |
Example
JSONStreamingAPI - startArray()
Opens an array within the parent JSON object.
Include the endArray() method to close the array.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - startArrayField(String fieldName)
Creates an array within the parent JSON object.
Surround this method with the startArray() and endArray() methods to open and close the array.
Name | Type | Description |
---|---|---|
fieldName | String | The name of the array. |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
JSONStreamingAPI - startObject()
Opens an object within the parent JSON object.
Requires the endObject() method to close the object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - writeBoolean(Boolean state)
Adds a Boolean value to the parent JSON object.
Name | Type | Description |
---|---|---|
state | Boolean | The boolean value to add to the parent JSON object. Valid values:
|
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
JSONStreamingAPI - writeBooleanField(String fieldName, Boolean value)
Adds a Boolean field and value to the parent JSON object.
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:
|
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
JSONStreamingAPI - writeFieldName(String name)
Adds a field name to the parent JSON object.
Name | Type | Description |
---|---|---|
name | String | Field name to add to the parent JSON object. |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - writeNull()
Adds a null value to the parent JSON object.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
JSONStreamingAPI - writeNullField(String fieldName)
Adds a field with a null value to the parent JSON object.
Name | Type | Description |
---|---|---|
fieldName | String | The name of the null field. |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
JSONStreamingAPI - writeNumberField(String fieldName, String encodedValue)
Adds a number field and value to the parent JSON object.
Name | Type | Description |
---|---|---|
fieldName | String | The name of the number field. |
encodedValue | String | The value of the number field. |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - writeRaw(String text)
Adds a raw value to the parent JSON object.
Name | Type | Description |
---|---|---|
text | String | Raw text to add to the parent JSON object. |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
JSONStreamingAPI - writeString(String text)
Adds a string value to the parent JSON object.
Name | Type | Description |
---|---|---|
text | String | The string value to add to the parent JSON object. |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
JSONStreamingAPI - writeStringField(String fieldName, String value)
Adds a string field and value to the parent JSON object.
Name | Type | Description |
---|---|---|
fieldName | String | The name of the field to add to the parent JSON object. |
value | String | The value of the field. |
Type | Description |
---|---|
JSONStreamingAPI | Streaming JSON object used to construct the payload. |
Example
This example shows how to create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
On this page
- API call order
- Size limits
- Example
- JSONStreamingAPI - close()
- JSONStreamingAPI - disablePrettyPrint()
- JSONStreamingAPI - enablePrettyPrint()
- JSONStreamingAPI - endArray()
- JSONStreamingAPI - endObject()
- JSONStreamingAPI - getAttachmentId()
- JSONStreamingAPI - getJSONString()
- JSONStreamingAPI - startArray()
- JSONStreamingAPI - startArrayField(String fieldName)
- JSONStreamingAPI - startObject()
- JSONStreamingAPI - writeBoolean(Boolean state)
- JSONStreamingAPI - writeBooleanField(String fieldName, Boolean value)
- JSONStreamingAPI - writeFieldName(String name)
- JSONStreamingAPI - writeNull()
- JSONStreamingAPI - writeNullField(String fieldName)
- JSONStreamingAPI - writeNumberField(String fieldName, String encodedValue)
- JSONStreamingAPI - writeRaw(String text)
- JSONStreamingAPI - writeString(String text)
- JSONStreamingAPI - writeStringField(String fieldName, String value)