JSONtransforms
This feature is only enabled on certain environments and tenants. Please contact Support for more information about this feature.
With the Transforms API we are able to support many types of transform definitions. This document describes the transform type JSONtransforms.
In this transform we are able to convert JSON content to requests and responses that are compatible with the Spark Execute API. JSONata is a "lightweight query and transformation language for JSON data". You can test your JSONata transforms in the JSONata Exerciser.
We recommend this transform type if you have a complex JSON transformation that you would like to perform on a single request and response.

Transform document
Transform documents are used to define the code relating to a transform. For JSONtransforms, the transform document is a JSON document defined by the following objects:
starget_api_version
Optional parameter.
This can be either v3 or v4 depending on whether to target the Execute API (v3) or Execute API (v4).
If omitted, then the default is v3.
input_body_transform
Optional parameter.
Single string containing the code for the input transform. Any double quotation marks " need to be escaped, i.e. " is replaced with \". This will be processed against the request body to the /transforms endpoint.
If omitted, no transformation will take place.
The result will automatically be put under the Execute API inputs object.
See the Example for more details.
output_body_transform
Optional parameter.
Single string containing the code for the output transform. Any double quotation marks " need to be escaped, i.e. " is replaced with \".
If omitted, no transformation will take place.
This will be processed against the response body of the Execute API.
See the Example for more details.
Build transforms
To build transforms you can follow the instructions for the specific transform on this page. For JavaScript developers there is also the Node Transform Document Builder that can be used to assist with the development.
Transforms API
These details are specific to this transform in addition to information in Transforms API.
Request headers
In addition to the Transforms API Request headers, these are specific to this transform.
Meta parameters are included in the request headers to keep the request body as generic as possible to conform to the calling system format.
Content-Type
application/json
x-meta
Optional parameter.
If using target_api_version v4, this should contain a single string containing a JSON object with key value pairs of the Execute API (v4) Request body parameters. Any double quotation marks " need to be escaped, i.e. " is replaced with \".
Example:
"{\"version_id\":\"86da8bea-b900-4bf2-8bcf-6a365ac91a4d\"}"
x-request-meta
Optional parameter.
If using target_api_version v3, this should contain a single string containing a JSON object with key value pairs of the Execute API (v3) request_meta parameters. Any double quotation marks " need to be escaped, i.e. " is replaced with \".
Example:
"{\"call_purpose\":\"Transform mainframe request\"}"
Request body
Content must be in JSON.
Limitations
The API call has a maximum lifetime of
29 s.The API request can include a maximum payload size of
6 MB.
Response headers
Content-Type
application/json
x-meta
Optional parameter.
If using target_api_version v4, this should contain a single string containing a JSON object with key value pairs of the Execute API (v4) Request body parameters. Any double quotation marks " need to be escaped, i.e. " is replaced with \".
Example:
"{\"version_id\":\"86da8bea-b900-4bf2-8bcf-6a365ac91a4d\"}"
x-request-meta
Optional parameter.
If using target_api_version v3, this should contain a single string containing a JSON object with key value pairs of the Execute API (v3) request_meta parameters. Any double quotation marks " need to be escaped, i.e. " is replaced with \".
Example:
"{\"call_purpose\":\"Transform mainframe request\"}"
Response body
Content will be in JSON.
If the Spark Execute API encounters an error, the error from the Execute API will be returned.
HTTP status code
By default the status code for a successful transformation will be 200. You can also ask the transform to return a custom status code that can be consumed by your application.
If the transformation was successful and the completed output transform includes the key spark_transform_response_httpstatuscode then Spark will use the value of this key as the returned status code.
For example:
This would result in the HTTP status code returned as 422 Unprocessable Entity
Example
In this example the calling system would like to perform addition and multiplication operations but it is in a different format to the Spark service. The Spark service has its inputs and outputs defined as:
For this example we will be using the Execute API (v3).
Xoutput_add=Xinput_add_1+Xinput_add_2Xoutput_multiply=Xinput_multiply_1*Xinput_multiply_2For the Spark Execute API (v3) call, we also want to note the
call_purpose.In the response, we would like to include the Execute API (v3) response_meta
call_id.
The below illustrates how the request is transformed to match the Spark Execute API (v3) format and how the response is transformed to match the required system response.
Create the transform document
The transform can be assembled into the transform document as attached below.
Follow the instructions in Create new transform documents to create a new transform in the folder of your choice.
The Transform type is
JSONata_v1.0.1.Since we are using Execute API (v3), choose Target API version as
v3.Copy and paste the JSONata transforms above in to the Request transform and Response transform respectively.
Alternatively the document can be manually created and uploaded to Spark using the New transforms feature.
The
transform_typeisJSONata_v1.0.1.Since we are using Execute API (v3), the
target_api_versionisv3.Both the
input_body_transformandoutput_body_transformeach must be a single string containing the code for the transform.Remove any lines containing comments.
Any double quotation marks
"need to be escaped, i.e."is replaced with\".Note that JSONata allows for single quotation marks
'to be interchanged with double quotation marks". If'are used exclusively in lieu or", then the escape character is not needed.
If you are using Visual Studio Code, you can use the Join lines feature to make it easy to combine multiple lines into a single string.
Select the transform text that you would like to combine onto a single line.
Access the Command Palette
F1orCtrl+Shift+Pon Windows orShift+⌘+Pon Mac.Type in the command Join lines and select it.
As an alternative to Join lines, line breaks
Ctrl+Entercan be replaced with the new line character\n.
Follow the instructions on Transform documents to upload the transform document to Spark.
Sample request
Sample response
Sample JSONata
Convert JSON "records" table to array table
Convert items with index suffices into an array of objects
Select items with the index suffices _# identified in number_of_plans.
Last updated
