src/melon/modules/json/json_module.c
static TByte stringifyFunc(VM* vm)
{
    melM_arg(vm, value, MELON_TYPE_NONE, 0);
    melM_argOptional(vm, prettify, MELON_TYPE_BOOL, 1);

    cJSON* obj = serializeJson(vm, value);

    if (obj == NULL)
    {
        melM_vstackPushNull(&vm->stack);
        return 1;
    }

    TBool shouldPrettify = 
        prettify->type == MELON_TYPE_BOOL 
        && prettify->pack.value.boolean
    ;

    char* jsonStr = shouldPrettify ? cJSON_Print(obj) : cJSON_PrintUnformatted(obj);
    melM_vstackPushGCItem(&vm->stack, melNewString(vm, jsonStr, strlen(jsonStr)));

    free(jsonStr);
    cJSON_Delete(obj);

    return 1;
}
/***
 * Serializes a given value to a JSON string.
 * 
 * @arg value The value that should be JSON serialized
 * @arg prettify? `true` If the output should be prettified, defaults to `false`
 * 
 * @returns A JSON string representing `value` or `null` if serialization failed.
 */
Serializes a given value to a JSON string.

@arg value The value that should be JSON serialized
@arg prettify. `true` If the output should be prettified, defaults to `false`

@returns A JSON string representing `value` or `null` if serialization failed.
Serializes a given value to a JSON string . @arg value The value that should be JSON serialized @arg prettify . ` true ` If the output should be prettified defaults to ` false ` @returns A JSON string representing ` value ` or ` null ` if serialization failed .
static TByte stringifyFunc(VM* vm)
{
    melM_arg(vm, value, MELON_TYPE_NONE, 0);
    melM_argOptional(vm, prettify, MELON_TYPE_BOOL, 1);
    cJSON* obj = serializeJson(vm, value);
    if (obj == NULL)
    {
        melM_vstackPushNull(&vm->stack);
        return 1;
    }
    TBool shouldPrettify = 
        prettify->type == MELON_TYPE_BOOL 
        && prettify->pack.value.boolean
    ;
    char* jsonStr = shouldPrettify ? cJSON_Print(obj) : cJSON_PrintUnformatted(obj);
    melM_vstackPushGCItem(&vm->stack, melNewString(vm, jsonStr, strlen(jsonStr)));
    free(jsonStr);
    cJSON_Delete(obj);
    return 1;
}
static TByte stringifyFunc ( VM * vm ) { melM_arg ( vm , value , MELON_TYPE_NONE , 0 ) ; melM_argOptional ( vm , prettify , MELON_TYPE_BOOL , 1 ) ; cJSON * obj = serializeJson ( vm , value ) ; if ( obj == NULL ) { melM_vstackPushNull ( & vm -> stack ) ; return 1 ; } TBool shouldPrettify = prettify -> type == MELON_TYPE_BOOL && prettify -> pack . value . boolean ; char * jsonStr = shouldPrettify ? cJSON_Print ( obj ) : cJSON_PrintUnformatted ( obj ) ; melM_vstackPushGCItem ( & vm -> stack , melNewString ( vm , jsonStr , strlen ( jsonStr ) ) ) ; free ( jsonStr ) ; cJSON_Delete ( obj ) ; return 1 ; }
Serializes a given value to a JSON string.
Serializes a given value to a JSON string .