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

D RXS_FormatJson...
D                 PR                  Extproc('RXS_FormatJson') Opdesc
D                                     Like(RXS_Var16Mv_t) Rtnparm

Returns the JSON provided in pInput formatted based on the options set in pFormatJsonDS.

D  pInput                             Like(RXS_Var16Mv_t) Const
D                                     Options(*Omit:*Varsize)

Input JSON to be reformatted

D  pFormatJsonDS                      LikeDS(RXS_FormatJsonDS_t)
D                                     Options(*Varsize:*Nopass)

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

D RXS_FormatJsonDS_t...
D                 DS                  Qualified Template Inz
 
D   ReturnedErrorInfo...
D                                     LikeDS(RXS_ReturnedErrorInfoDS_t) Inz
 
D   DataStructureType...
D                                5I 0 Inz(RXS_DS_TYPE_FORMATJSON)

Internal use only

D   OnErrorMessageType...
D                                5I 0

Internal use only

D   Prettify                      N   Inz(RXS_YES)

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:

  • RXS_YES
  • RXS_NO

Default Value: RXS_YES

D   MultipleLines...
D                                 N   Inz(RXS_YES)

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:

  • RXS_YES
  • RXS_NO

Default Value: RXS_YES

D   UseCRLF                       N   Inz(RXS_NO)

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:

  • RXS_YES
  • RXS_NO

Default Value: RXS_NO

D   SpaceBrackets...
D                                 N   Inz(RXS_YES)

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:

  • RXS_YES
  • RXS_NO

Default Value: RXS_YES

D   SpaceCommas                   N   Inz(RXS_YES)

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:

  • RXS_YES
  • RXS_NO

Default Value: RXS_YES

D   SpaceColons                   N   Inz(RXS_YES)

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:

  • RXS_YES
  • RXS_NO

Default Value: RXS_YES

D   IndentTabs                    N   Inz(RXS_NO)

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:

  • RXS_YES
  • RXS_NO

Default Value: RXS_NO

D   IndentSize                   3U 0 Inz(2)

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: 2

D   InputCcsid...
D                               10I 0 Inz(RXS_CCSID_JOB)

Specifies the CCSID of the data being passed into the JSON composition subprocedures. Default is job CCSID.

Default Value: RXS_CCSID_JOB

D   OutputCcsid...
D                               10I 0 Inz(RXS_CCSID_JOB)

Specifies the CCSID that the JSON will be output as from RXS_GetJsonString(). Default is job CCSID.

Default Value: RXS_CCSID_JOB

D   InputStmf...
D                                     Like(RXS_Var1Kv_t)

Specifies an IFS path to a JSON file to use as input instead of the pInput parm.

D   OutputStmf...
D                                     Like(RXS_Var1Kv_t)

Specifies an IFS path to write the formatted output to.

D   InputPointer...
D                                 *   Inz(*Null)

Internal use only

D   InputLength...
D                               10U 0 Inz(0)

Internal use only

D   OutputPointer...
D                                 *   Inz(*Null)

Internal use only

D   OutputLength...
D                               10U 0 Inz(0)

Internal use only