Integration Server 10.5 | Built-In Services Reference Guide | JSON Folder | pub.json:documentToJSONString
 
pub.json:documentToJSONString
WmPublic. Converts a document (IData object) to a JSON string.
Input Parameters
document
Document The document (IData object) to be converted to a JSON string.
prettyPrint
String Optional. Formats the jsonString output parameter for human readability by adding carriage returns and indentation to the JSON content. Set to:
*true to format jsonString output variable for human readability.
*false to leave the jsonString output variable 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 configuration parameter. For more information about watt.server.json.prettyPrint, see webMethods Integration Server Administrator’s Guide.
Output Parameters
jsonString
String JSON string resulting from the conversion of document.
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:documentToJSONString to turn a document (IData object) in the pipeline into a string of JSON content.
2. Call pub.client:http to send the JSON string as an HTTP request.
3. Set the Content-Type header field to application/json.
When creating a JSON text with pub.json:documentToJSONString, 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 text 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. Combining this with additional key/value pairs leads to unpredictable results.
The JSON standard requires that field names be enclosed in double quotes. However, you may need the service to produce unquoted field names if the generated JSON text will be processed by an older JavaScript interpreter. The watt.server.json.quoteFieldNames server configuration parameter determines whether the pub.json:documentToJSONString service encloses all generated JSON field names in double quotes. Set this parameter to true instruct the pub.json:documentToJSONString service to enclose field names in quotes in the output JSON text. Set this parameter to false to instruct the service to omit the double quotes around field names in the generated JSON text. The default is true.
Note:
Use caution when setting watt.server.json.quoteFieldNames to false as this causes the pub.json:documentToJSONString service to generate non-standard JSON text. This can cause interoperability issues if the JSON text is sent to other organizations.