# RXS_GetJsonStringLen() This subprocedure is used to calculate the length of a JSON string that has been composed by [RXS_CreateJson()](https://isupport.katointegrations.com/rxs/3.5/rxs_createjson.md) and the other JSON composition subprocedures. ## Subprocedure Prototype ```rpgle D RXS_GetJsonStringLen... D PR 10U 0 Extproc('RXS_GetJsonStringLen') D Opdesc // The CreateJson data structure where the JSON data is being composed. // This is the data structure that was specified in the first parameter // when RXS_CreateJson() was called. D pCreateJsonDS LikeDS(RXS_CreateJsonDS_t) D Options(*Varsize) ``` ## Example Code ### Ex. 1: Get length of JSON string in memory ```rpgle *-------------------------------------------------------------- * This example creates a simple JSON object, adds a string data * field to it, and retrieves the length of the string in * memory. *-------------------------------------------------------------- H DFTACTGRP(*NO) BNDDIR('RXSBND') ACTGRP(*CALLER) /copy QRPGLECPY,RXSCB D JsonLen S 10U 0 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_ComposeJsonString( 'hello' : 'world' : RootDS ); // Composed JSON looks like: {"hello":"world"} JsonLen = RXS_GetJsonStringLen( CreateJsonDS ); // JsonLen is: 17 RXS_DestroyJson( CreateJsonDS ); *INLR = *ON; /end-free ``` ## Data Structures ### RXS_CreateJsonDS_t ```rpgle D RXS_CreateJsonDS_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_CREATEJSON) D OnErrorMessageType... D 5I 0 // If set to RXS_YES, JSON retrieved with RXS_GetJsonString() will be // formatted with whitespace to be "pretty" and more human readable. 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: RXS_NO D Prettify N Inz(RXS_NO) // If set to RXS_JSON_STRUCTURE_OBJECT, the JSON document being created // will begin with a root JSON object. If set to RXS_JSON_STRUCTURE_ARRAY, // it will begin with a root JSON array. // Valid values: RXS_JSON_STRUCTURE_OBJECT, RXS_JSON_STRUCTURE_ARRAY // Default: RXS_JSON_STRUCTURE_OBJECT D JsonStructureType... D N Inz(RXS_JSON_STRUCTURE_OBJECT) // Internal use only D JsonStructurePtr... D * Inz(*Null) // 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 value // passed to RXS_ComposeJsonString() (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) ```