Skip to end of banner
Go to start of banner

toJson - ex

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Availability

This routine is available starting with katl-commons 4.0.17

Syntax

toJson(<any struct, array or primitive type> [, convertEmptyFields, writeNull])

Description

Converts any given struct, array or primitive parameter to a JSON string.

By default, the JSON resulted from the conversion also contains the empty fields (in the case of structures for example) with null values. If you want these to be excepted from the conversion, you will have to set the convertEmptyFields flag to false.

Parameters

Parameter name

Type

Required

Description

<any struct, array or primitive type>

variable: primitive type, array or struct

Yes

The variable to be converted to JSON.

convertEmptyFieldsbooleanNoFlag that indicates if empty fields should be converted (if missing or true) or excepted
writeNullbooleanNo

If true: an empty field will have null value - ex: "emptyField": null

If false: an empty field will have empty string value - ex: "emptyField": ""

Note: the behavior described above applies only for the convertEmptyFields flag set to true.

Return type

string

Example

You can look at this routine as the preparatory one for the integration with other systems. You build your data structure and then you convert your struct to json to be sent to an external system. 

 


See also


  • No labels