name: duk_json_encode proto: | const char *duk_json_encode(duk_context *ctx, duk_idx_t idx); stack: | [ ... val! ... ] -> [ ... json_val! ... ] summary: |

Encodes an arbitrary value into its JSON representation as an in-place operation. Returns pointer to the resulting string for convenience.

example: | duk_push_object(ctx); duk_push_int(ctx, 42); duk_put_prop_string(ctx, -2, "meaningOfLife"); printf("JSON encoded: %s\n", duk_json_encode(ctx, -1)); duk_pop(ctx); /* Output: * JSON encoded: {"meaningOfLife":42} */ tags: - codec - json seealso: - duk_json_decode introduced: 1.0.0