Converts a JSON object to a JSON string.

C Language

int lr_json_stringify( "JsonObject=<parameter name>", "Format=<auto|compact|indented>" "OutputParam=<parameter name>" );


JsonObject The name of the parameter that stores the handle of the JSON object created by lr_eval_json.
FormatOptional. The spacing and line return layout of the returned string. One of:
  • compact - No white space. Suitable for processing in code.
  • indented (Default) - Easier for user to read.
  • auto - Output is compact on the Controller and indented in the VuGen log.
OutputParam The name of a parameter to store the output string.

lr_json_stringify writes the string equivalent of a JSON object to a parameter. The object is not changed.

This function is not recorded. You can insert it manually into your script.

Return Values

This function returns 0 on success and -1 on failure.


Parameterization is not applicable to this function.


This example shows the use of lr_json_stringify with different formats.

    char *json_input = 
                    "[ {\"productId\":12343,\"quantity\":4}, " 
                    "  {\"productId\":39293,\"quantity\":2} ]" 
    lr_save_string (json_input, "JSON_Input"); 
    lr_eval_json ("Buffer={JSON_Input}", "JsonObject=JSON_Param");
    lr_json_stringify("JsonObject=JSON_Param","Format=compact","OutputParam=Result",LAST );
    lr_output_message("Compact JSON is : %s", lr_eval_string("{Result}"));
    lr_json_stringify("JsonObject=JSON_Param","Format=indented","OutputParam=Result",LAST );
    lr_output_message("Indented JSON is : %s", lr_eval_string("{Result}"));
    lr_json_stringify("JsonObject=JSON_Param","Format=auto","OutputParam=Result",LAST );
    // Result is indented in VuGen and Compact on the Controller.

Action.c(21): Compact JSON is : {"cart":{"customerId":1343,"lineItems":[{"productId":12343,"quantity":4},{"productId":39293,"quantity":2}]}}

Action.c(25): Indented JSON is : {
    "cart": {
        "customerId": 1343,
        "lineItems": [
                "productId": 12343,
                "quantity": 4
                "productId": 39293,
                "quantity": 2