For AI agents: the complete documentation index is available at /hclapi/llms.txt, the full documentation bundle is available at /hclapi/llms-full.txt, and this page is available as Markdown at /hclapi/docs/manifest/functions/encoding/json_encode.md.

json_encode

Serializes any HCL data structure (primitive, map, object, list) into a valid JSON string.

Signature

json_encode(value: any) -> string

Parameters

ParameterTypeRequiredDescription
valueanyyesThe value or data structure to serialize

Return value

Returns the documented result for the function signature.

Example

endpoint "GET /api/v1/products/{id}" {
  pipeline {
    redis "cache_write" {
      connection = connection.redis.cache
      command    = "SET"
      key        = "product:${ctx.request.path.id}"
      value      = json_encode(steps.find_product.result)
      ttl        = "30m"
    }
  }
}