RXS_FormatJson()
This subprocedure is used to format JSON. This can either be used to expand the JSON with additional whitespace, lines feeds, and indentation, or it can be used to take an existing JSON document and “minify” it to compress it into the smallest space possible by removing whitespace and line feeds. This subprocedure provides more formatting capabilities than the Prettify option available for RXS_CreateJson() in the RXS_CreateJsonDS_t data structure.
Subprocedure Prototype
|
Returns the JSON provided in pInput formatted based on the options set in pFormatJsonDS. |
|
Input JSON to be reformatted |
|
RXS_FormatJsonDS_t data structure which controls how RXS_FormatJson() functions. |
Example Code
*--------------------------------------------------------------
* This example expands a JSON document similar to the Prettify
* option available for RXS_CreateJson().
*--------------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER)
/copy QRPGLECPY,RXSCB
D InJSON S Like(RXS_Var64Kv_t)
D OutJSON S Like(RXS_Var64Kv_t)
D FormatJsonDS DS LikeDS(RXS_CreateJsonDS_t)
/free
// Set up a basic JSON document
InJSON = '{ "item": { "id": 7, "name": "headlight fluid",'
+ ' "price": 12.50 } }';
RXS_ResetDS( FormatJsonDS : RXS_DS_TYPE_FORMATJSON );
// We're going to use the default options for FormatJsonDS
// which will "Prettify" our JSON similar to RXS_CreateJson().
OutJSON = RXS_FormatJson( InJSON : FormatJsonDS );
// OutJSON contents:
//
// {
// "item": {
// "id": 7,
// "name": "headlight fluid",
// "price": 12.50
// }
// }
*INLR = *ON;
/end-free
Data Structures
|
|
|
|
|
Internal use only |
|
Internal use only |
|
If set to RXS_YES, JSON returned will be formatted based on the remaining options in this data structure. If set to RXS_NO, JSON will be returned in a compact form with as little whitespace as possible. Valid Values:
Default Value: |
|
If set to RXS_YES, JSON returned will be split into multiple lines for readability. If set to RXS_NO, JSON will be returned in a single line. Valid Values:
Default Value: |
|
If set to RXS_YES, JSON returned will use both the "carriage return" and "line feed" (CRLF) for line endings. If set to RXS_NO, JSON will only use the "line feed" (LF) for line endings. Valid Values:
Default Value: |
|
If set to RXS_YES, JSON returned will include spaces around the object brackets { } and the array brackets [ ]. If set to RXS_NO, JSON will not add spaces around the brackets. Valid Values:
Default Value: |
|
If set to RXS_YES, JSON returned will include spaces around the commas used to separate elements in objects and arrays. If set to RXS_NO, JSON will not add spaces around the commas. Valid Values:
Default Value: |
|
If set to RXS_YES, JSON returned will include spaces around the colons used to separate keys and values within an object. If set to RXS_NO, JSON will not add spaces around the colons. Valid Values:
Default Value: |
|
If set to RXS_YES, JSON returned will use Tab to indent instead of spaces. If set to RXS_NO, JSON will use spaces. Valid Values:
Default Value: |
|
Specifies how the JSON returned will be indented. This interacts with IndentTabs to control how many Tab or spaces will be used to indent. Default Value: |
|
Specifies the CCSID of the data being passed into the JSON composition subprocedures. Default is job CCSID. Default Value: |
|
Specifies the CCSID that the JSON will be output as from RXS_GetJsonString(). Default is job CCSID. Default Value: |
|
Specifies an IFS path to a JSON file to use as input instead of the pInput parm. |
|
Specifies an IFS path to write the formatted output to. |
|
Internal use only |
|
Internal use only |
|
Internal use only |
|
Internal use only |