# RXS_ComposeJsonBoolean() This subprocedure is used to add a JSON boolean element to a parent JSON Object or Array. ## Subprocedure Prototype ```rpgle D RXS_ComposeJsonBoolean... D PR Extproc('RXS_ComposeJsonBoolean') D Opdesc // Name to assign to JSON boolean data element. If being added to an array, // the value of this parameter should be *OMIT. D pName Const Like(RXS_Var64Kv_t) D Options(*Omit:*Varsize) // Pass RXS_JSON_TRUE if the JSON boolean data element should be true, // RXS_JSON_FALSE if the JSON boolean data element should be false. D pBoolean N Const // RXS_JsonStructureDS_t data structure containing a parent JSON Object or // Json Array. D pStructureDS Const LikeDS(RXS_JsonStructureDS_t) D Options(*Varsize) ``` ## Example Code ### Ex. 1: Create JSON object with boolean element ```rpgle *-------------------------------------------------------------- * This example creates a simple JSON object, adds a boolean * data field 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) /free RXS_ResetDS( CreateJsonDS : RXS_DS_TYPE_CREATEJSON ); RXS_ResetDS( RootDS : RXS_DS_TYPE_JSONSTRUCTURE ); CreateJsonDS.JsonStructureType = RXS_JSON_STRUCTURE_OBJECT; RootDS = RXS_CreateJson( CreateJsonDS ); RXS_ComposeJsonBoolean( 'value' : RXS_JSON_TRUE : RootDS ); RXS_ComposeJsonBoolean( 'enabled' : RXS_JSON_FALSE : RootDS ); JSON = RXS_GetJsonString( CreateJsonDS ); // JSON looks like: // // {"value":true,"enabled":false} RXS_DestroyJson( CreateJsonDS ); *INLR = *ON; /end-free ``` ### Ex. 2: Create JSON array with multiple boolean elements ```rpgle *-------------------------------------------------------------- * This example creates a simple JSON array, adds 5 boolean data * fields 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 i S 3U 0 /free RXS_ResetDS( CreateJsonDS : RXS_DS_TYPE_CREATEJSON ); RXS_ResetDS( RootDS : RXS_DS_TYPE_JSONSTRUCTURE ); CreateJsonDS.JsonStructureType = RXS_JSON_STRUCTURE_ARRAY; RootDS = RXS_CreateJson( CreateJsonDS ); for i = 1 to 5; RXS_ComposeJsonBoolean( *OMIT : RXS_JSON_TRUE : RootDS ); endfor; JSON = RXS_GetJsonString( CreateJsonDS ); // JSON looks like: // // [true,true,true,true,true] RXS_DestroyJson( CreateJsonDS ); *INLR = *ON; /end-free ``` ## Data Structures ### RXS_JsonStructureDS_t ```rpgle D RXS_JsonStructureDS_t... D DS Qualified Template Inz D ReturnedErrorInfo... D LikeDS(RXS_ReturnedErrorInfoDS_t) Inz // Internal use only D DataStructureType... D 5I 0 Inz(RXS_DS_TYPE_JSONSTRUCTURE) D OnErrorMessageType... D 5I 0 // Internal use only D JsonStructurePtr... D * Inz(*Null) // Internal use only D JsonStructureType... D N Inz(RXS_JSON_STRUCTURE_OBJECT) // Specifies the CCSID of the data being passed into the JSON composition // subprocedures. Default is job CCSID. // Default: RXS_CCSID_JOB D InputCcsid... 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: RXS_CCSID_JOB D OutputCcsid... D 10I 0 Inz(RXS_CCSID_JOB) // Determines whether to trim leading and trailing spaces from each // variable passed to the JSON composition subprocedures (RXS_YES), or to // leave all spaces in place (RXS_NO). // Valid values: RXS_YES, RXS_NO // Default: RXS_NO D TrimVariables... D N Inz(RXS_NO) ```