RXS_ComposeJsonObject()

This subprocedure is used to add a JSON object element to a parent JSON Object or Array.

Subprocedure Prototype

D RXS_ComposeJsonObject...
D                 PR                  Extproc('RXS_ComposeJsonObject')
D                                     Opdesc
D                                     LikeDS(RXS_JsonStructureDS_t)
 
D  pName                              Const Like(RXS_Var64Kv_t)
D                                     Options(*Omit:*Varsize)

Name to assign to JSON object. If being added to an array, the value of this parameter should be *OMIT.

D  pStructureDS                       Const LikeDS(RXS_JsonStructureDS_t)

RXS_JsonStructureDS_t data structure containing a parent JSON Object or Json Array.

Example Code

*--------------------------------------------------------------
* This example creates a simple JSON object, adds a child object
* to it, retrieves the created JSON, and then calls
* RXS_DestroyJson() to clean up.
*--------------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER)

 /copy QRPGLECPY,RXSCB

D JSON            S                   Like(RXS_Var64Kv_t)

D CreateJsonDS    DS                  LikeDS(RXS_CreateJsonDS_t)
D RootDS          DS                  LikeDS(RXS_JsonStructureDS_t)
D ChildDS         DS                  LikeDS(RXS_JsonStructureDS_t)
 /free
   RXS_ResetDS( CreateJsonDS : RXS_DS_TYPE_CREATEJSON );
   RXS_ResetDS( RootDS : RXS_DS_TYPE_JSONSTRUCTURE );
   RXS_ResetDS( ChildDS : RXS_DS_TYPE_JSONSTRUCTURE );
   
   CreateJsonDS.JsonStructureType = RXS_JSON_STRUCTURE_OBJECT;
   RootDS = RXS_CreateJson( CreateJsonDS );

   ChildDS = RXS_ComposeJsonObject( 'child' : RootDS );

   JSON = RXS_GetJsonString( CreateJsonDS );
   // JSON looks like:
   //
   // { "child": {} }

   RXS_DestroyJson( CreateJsonDS );

   *INLR = *ON;
 /end-free
*--------------------------------------------------------------
* This example creates a simple JSON array, adds 3 child objects 
* to it, retrieves the created JSON, and then calls
* RXS_DestroyJson() to clean up.
*--------------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER)

 /copy QRPGLECPY,RXSCB

D JSON            S                   Like(RXS_Var64Kv_t)

D CreateJsonDS    DS                  LikeDS(RXS_CreateJsonDS_t)
D RootDS          DS                  LikeDS(RXS_JsonStructureDS_t)
D ChildDS         DS                  LikeDS(RXS_JsonStructureDS_t)
D i               S              3U 0
 /free
   RXS_ResetDS( CreateJsonDS : RXS_DS_TYPE_CREATEJSON );
   RXS_ResetDS( RootDS : RXS_DS_TYPE_JSONSTRUCTURE );
   RXS_ResetDS( ChildDS : RXS_DS_TYPE_JSONSTRUCTURE );
   
   CreateJsonDS.JsonStructureType = RXS_JSON_STRUCTURE_ARRAY;
   RootDS = RXS_CreateJson( CreateJsonDS );

   for i = 1 to 3;
     ChildDS = RXS_ComposeJsonObject( *OMIT : RootDS );
     RXS_ComposeJsonString( 'value' : %Char(i) : ChildDS );
   endfor;

   JSON = RXS_GetJsonString( CreateJsonDS );
   // JSON looks like:
   //
   // [{"value": "1"}, {"value": "2"}, {"value": "3"}]

   RXS_DestroyJson( CreateJsonDS );

   *INLR = *ON;
 /end-free
*--------------------------------------------------------------
* This example creates a simple JSON object, adds a child object
* to it, retrieves the created JSON, and then calls
* RXS_DestroyJson() to clean up.
*--------------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER)

 /define RXSV6R1
 /copy QRPGLECPY,RXSCB

D JSON            S                   Like(RXS_Var64Kv_t)

D CreateJsonDS    DS                  LikeDS(RXS_CreateJsonDS_t)
D RootDS          DS                  LikeDS(RXS_JsonStructureDS_t)
D ChildDS         DS                  LikeDS(RXS_JsonStructureDS_t)
 /free
   RXS_ResetDS( CreateJsonDS : RXS_DS_TYPE_CREATEJSON );
   RXS_ResetDS( RootDS : RXS_DS_TYPE_JSONSTRUCTURE );
   RXS_ResetDS( ChildDS : RXS_DS_TYPE_JSONSTRUCTURE );
   
   CreateJsonDS.JsonStructureType = RXS_JSON_STRUCTURE_OBJECT;
   RootDS = RXS_CreateJson( CreateJsonDS );

   ChildDS = RXS_ComposeJsonObject( 'child' : RootDS );

   RXS_GetJsonString( JSON : CreateJsonDS );
   // JSON looks like:
   //
   // { "child": {} }

   RXS_DestroyJson( CreateJsonDS );

   *INLR = *ON;
 /end-free
*--------------------------------------------------------------
* This example creates a simple JSON array, adds 3 child objects 
* to it, retrieves the created JSON, and then calls
* RXS_DestroyJson() to clean up.
*--------------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER)

 /define RXSV6R1
 /copy QRPGLECPY,RXSCB

D JSON            S                   Like(RXS_Var64Kv_t)

D CreateJsonDS    DS                  LikeDS(RXS_CreateJsonDS_t)
D RootDS          DS                  LikeDS(RXS_JsonStructureDS_t)
D ChildDS         DS                  LikeDS(RXS_JsonStructureDS_t)
D i               S              3U 0
 /free
   RXS_ResetDS( CreateJsonDS : RXS_DS_TYPE_CREATEJSON );
   RXS_ResetDS( RootDS : RXS_DS_TYPE_JSONSTRUCTURE );
   RXS_ResetDS( ChildDS : RXS_DS_TYPE_JSONSTRUCTURE );
   
   CreateJsonDS.JsonStructureType = RXS_JSON_STRUCTURE_ARRAY;
   RootDS = RXS_CreateJson( CreateJsonDS );

   for i = 1 to 3;
     ChildDS = RXS_ComposeJsonObject( *OMIT : RootDS );
     RXS_ComposeJsonString( 'value' : %Char(i) : ChildDS );
   endfor;

   RXS_GetJsonString( JSON : CreateJsonDS );
   // JSON looks like:
   //
   // [{"value": "1"}, {"value": "2"}, {"value": "3"}]

   RXS_DestroyJson( CreateJsonDS );

   *INLR = *ON;
 /end-free

Data Structures

D RXS_JsonStructureDS_t...
D                 DS                  Qualified Template Inz
 
D   ReturnedErrorInfo...
D                                     LikeDS(RXS_ReturnedErrorInfoDS_t) Inz
 
D   DataStructureType...
D                                5I 0 Inz(RXS_DS_TYPE_JSONSTRUCTURE)

Internal use only

D   OnErrorMessageType...
D                                5I 0
 
D   JsonStructureType...
D                                 N   Inz(RXS_JSON_STRUCTURE_OBJECT)

Internal use only

D   JsonStructure@...
D                                 *   Inz(*Null)

Internal use only

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.

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.