Integration Server 11.1 | Built-In Services Reference Guide | JSON Folder | Summary of Elements in This Folder | pub.json:documentToJSON
 
pub.json:documentToJSON
WmPublic. Converts a document (IData object) to a JSON object.
Input Parameters
document
Document. The document (IData object) to be converted to a JSON object.
jsonDocumentTypeName
String. Optional. If specified, the transformation from Document (IData) to JSON object is based on the JSON document type. Any deviations from the provided JSON document might cause transformation errors.
This parameter must have the fully qualified name of a JSON document type on Integration Server against which the JSON content in document is validated. This parameter must be in the format: <Folder Name>:<JSON Document Type Name>. For example: data:employeeData
When this parameter is provided to the service, Integration Server ignores the following parameters and the corresponding server configuration parameters, if set.
*encodeDateAs and watt.server.json.encodeDateAs
*encodeStringAsNumber
*encodeStringAsBoolean
*encodeMapAsString and watt.server.json.encodeMapAsString
*encodeListsAndSetsAsArrays and watt.server.json.encodeListsAndSetsAsArrays
For more information about the server configuration parameters, see watt.server.
strict
String. Optional. Whether the service performs a strict or loose transformation based on the supplied jsonDocumentTypeName. Valid values are true and false.
The values of strict and jsonDocumentTypeName parameters together determine how Integration Server parses and converts Document (IData) to JSON object in the following manner:
*When strict is false and jsonDocumentTypeName is not specified, there is no change in the behavior.
*When strict is true and jsonDocumentTypeName is not specified, the service returns an exception.
*When strict is false and jsonDocumentTypeName is specified, the transformation from Document (IData) to JSON object is loosely based on the JSON document type. For conversion rules, see Table 2: Conversion of IData to JSON payload.
*When strict is true and jsonDocumentTypeName is specified, the transformation from Document (IData) to JSON object is strictly based on the JSON document type. The validation is performed first before the transformation, and any deviations lead to transformation errors.
There is no default value for this input parameter.
loadAs
String. Specifies the format in which you need the converted jsonObj. Set to:
*string to return jsonObj as a string. This is the default value.
*bytes to return jsonObj as a byte array.
*stream to return jsonObj as InputStream.
prettyPrint
String. Optional. Whether the service formats the jsonObj output parameter for human readability by adding carriage returns and indentation to the JSON content. Set to:
*true to format the jsonObj output variable for human readability.
*false to leave the jsonObj output parameter in its unformatted state. The service will not add any additional carriage returns or indentation to the JSON content.
*<null> to use the prettyPrint setting already in effect for the HTTP client making the request, as follows:
*If the HTTP client request includes jsonPrettyPrint=true in the URI, JSON pretty printing is in effect.
*If the HTTP client request includes jsonPrettyPrint=false in the URI, JSON pretty printing is not in effect.
*If the HTTP client request does not include the jsonPrettyPrint parameter, the service uses the value of the watt.server.json.prettyPrint server configuration parameter. For more information about the parameter, see watt.server.json.prettyPrint.
encodeDateAs
String. Optional. Specifies how java.util.Date instances in the document are encoded in the returned JSON object. Set to:
*long to encode java.util.Date instances as timestamps, specifically the number of milliseconds since Jan 1, 1970 00:00:00. The dates are encoded as JSON numbers.
*ISO8601 to encode java.util.Date instances as strings in a standard ISO format of: YYYY-MM-DD'T'HH:mm:ss.sssZ. The dates are encoded as JSON strings.
*ISO_LOCAL_DATE to encode java.util.Date instances as strings in a standard ISO format without an offset. For example, '2011-12-03'. The dates are encoded as JSON strings.
*ISO_DATE to encode java.util.Date instances as strings in a standard ISO format with the offset, if available. For example, '2011-12-03' or '2011-12-03+01:00'. The dates are encoded as JSON strings.
*ISO_ZONED_DATE_TIME to encode java.util.Date instances as strings in a standard ISO format with the offset and zone, if available. For example, '2011-12-03T10:15:30', '2011-12-03T10:15:30+01:00' or '2011-12-03T10:15:30+01:00[Europe/Paris]'. The dates are encoded as JSON strings.
*ISO_INSTANT to encode java.util.Date instances as strings in a standard ISO format in UTC. For example, '2011-12-03T10:15:30Z'. The dates are encoded as JSON strings.
*BASIC_ISO_DATE to encode java.util.Date instances as strings in a standard ISO format without an offset. For example, '20111203'. The dates are encoded as JSON strings.
*RFC_1123_DATE_TIME to encode java.util.Date instances as strings in a standard ISO format. For example, 'Tue, 3 Jun 2008 11:05:30 GMT'. The dates are encoded as JSON strings.
*Custom format in which dates are encoded as strings in the supplied pattern. The pattern must adhere to the date and time patterns as described in the java.text.SimpleDateFormat class in the Oracle Java API documentation. The dates are encoded as JSON strings.
*<null> to use the jsonDateEncoding setting already in effect for the HTTP client making the request, as follows:
*If the HTTP client request includes jsonDateEncoding=long in the URL, then java.util.Date instances are represented as timestamps, specifically the number of milliseconds since Jan 1, 1970 00:00:00. The dates are JSON numbers.
*If the HTTP client request includes jsonDateEncoding=ISO8601 in the URL, the java.util.Date instances are encoded as strings in a standard ISO format of: YYYY-MM-DD'T'HH:mm:ss.sssZ. The dates are JSON strings.
*If the HTTP client request includes jsonDateEncoding= format in the URL, the java.util.Date instances are encoded as strings in the supplied pattern. The pattern must adhere to the date and time patterns as described in the java.text.SimpleDateFormat class in the Oracle Java API documentation.
*If the HTTP client request does not include the jsonDateEncoding in the URL, the service uses the value of the watt.server.json.encodeDateAs parameter. For more information about the parameter, see watt.server.json.encodeDateAs
There is no default value for this input parameter.
encodeStringAsNumber
Boolean. Optional. Specifies whether the service encodes strings as numbers. Set to:
*true to convert all the numbers in the string format to numbers by removing the quotes.
*false to retain all the numbers in the string format.
*<null> to retain the original encoding in the request.
There is no default value for this input parameter.
encodeStringAsBoolean
Boolean. Optional. Specifies how the service handles boolean values in the string format. Set to:
*true to convert all the boolean values in the string format to boolean by removing the quotes.
*false to retain all the boolean values in the string format.
*<null> to retain the original encoding in the request.
There is no default value for this input parameter.
encodeMapAsString
Boolean. Optional. Specifies how the service encodes instances of java.util.Map. Set to:
*true to encode instances of java.util.Map as a JSON string.
*false to encode instances of java.util.Map as a nested JSON structure.
*<null> to use the value of watt.server.json.encodeMapAsString to determine the encoding. For more information about the parameter, see .
There is no default value for this parameter.
encodeListsAndSetsAsArrays
Boolean. Optional. Specifies how the service encodes instances of java.util.List or java.util.Set. Set to:
*true to encode instances of java.util.List or java.util.Set as arrays.
*false to encode instances of java.util.List or java.util.Set as a JSON string.
*<null> to use the value of watt.server.json.encodeListsAndSetsAsArrays to determine the encoding. For more information about the parameter, see watt.server.json.encodeListsAndSetsAsArrays.
There is no default value for this parameter.
Output Parameters
jsonObj
Object. Conditional. JSON of type byte array, string or stream (java.io.InputStream) resulting from the conversion of a document depending on the loadAs value.
Usage notes
To turn a document in a pipeline into a JSON response to send over HTTP, the application's service can:
1. Use pub.json:documentToJSON to turn a document (IData object) in the pipeline into a JSON object.
2. Call pub.client:http to send the JSON object as an HTTP request.
3. Set the Content-Type header field to application/json.
When creating a JSON object with pub.json:documentToJSON, if the document input parameter contains a $rootArray key with an array as its value, Integration Server discards the $rootArray name and transforms the array value into a JSON array. The resulting JSON object will contain only an unnamed array. $rootArray and key/value pairs cannot both appear in the input document. $rootArray indicates that the generated JSON text should consist only of an unnamed array. Therefore, avoid combining $rootArray with additional key/value pairs to prevent unpredictable results.
When strict=true, the validation of a JSON document against the JSON document type happens before transformation, and the validation exception, if any, contains the first error message, which is the result of the pub.json.schema:validate service execution. The validation errors from the pub.json.schema:validate service, if any, can be one or more in the service output. However, only the first error message is displayed in the pub.json:documentToJSON service exception.