> ## Documentation Index
> Fetch the complete documentation index at: https://errand.nuvrel.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# jsonencode

> Encode a value as a JSON string.

`jsonencode(val)` serializes `val` to a JSON string. Maps become objects, lists become arrays, strings, numbers, and booleans are encoded as their JSON equivalents.

## Signature

```
jsonencode(val any) string
```

## Example

Build a deployment metadata payload and pass it to an API endpoint:

```hcl theme={null}
variable "app" {
  type    = string
  default = "api"
}

variable "version" {
  type = string
}

variable "env" {
  type    = string
  default = "staging"
}

variable "build_timestamp" {
  description = "RFC 3339 build timestamp"
  type        = string
}

computed "deploy_payload" {
  description = "JSON payload for the deployment API"
  expression  = jsonencode({
    application = var.app
    version     = var.version
    environment = var.env
    deployed_at = var.build_timestamp
  })
}

task "notify-deploy" {
  description = "Record the deployment in the release tracker"
  commands = [
    "curl -X POST https://releases.example.com/api/deploys -H 'Content-Type: application/json' -d '${computed.deploy_payload}'",
  ]
}
```

## Notes

* The output is compact JSON (no extra spaces or newlines).
* Map keys are sorted alphabetically in the output.
* To parse a JSON string back to a value, use [`jsondecode`](/functions/encoding/jsondecode).
