Skip to content

Render Pkl configuration

Generate JSON, YAML, and PCF from Pkl configuration files for applications, deployment tools, and CI.

On this page

Coming in Elide 1.6.3. Evaluate a .pkl or .pcf file directly and send its rendered output to stdout. Use this to generate application configuration, feed deployment tools, or inspect a configuration before committing it. No Elide project is required.

Generate JSON or YAML

Start with config.pkl:

pkl
service = "api"
port = 8080
utf-8 · pkl · Lines: 2

Choose the format your application consumes and redirect the result to a file:

Terminal
shell
elide --format=json config.pkl > config.json
elide --format=yaml config.pkl > config.yaml

The JSON output contains service and port with the same values and types. The explicit run command works too:

Terminal
shell
elide run --format json config.pkl

Both .pkl and .pcf inputs accept the same options. For example, convert an existing PCF configuration to JSON:

Terminal
shell
elide --format=json config.pcf > config.json

Choose an output format

OptionOutputTypical use
--format=jsonJSONApplication settings and JSON-consuming tools
--format=yamlYAMLDeployment configuration
--format=pcfPkl Configuration FormatInspect evaluated configuration in Pkl notation
No --formatThe module’s configured output; PCF by defaultHonor a module’s own output definition

TOML output is not supported. An unsupported format fails with exit code 2.

Share configuration across files

Relative imports resolve from the input file, so a configuration can reuse nearby defaults even when invoked from another directory. For example, place defaults.pkl and config.pkl together under config/:

pkl
// defaults.pkl
port = 8080
utf-8 · pkl · Lines: 2
pkl
// config.pkl
import "defaults.pkl"

service = "api"
port = defaults.port
utf-8 · pkl · Lines: 5

From the repository root, render the configuration with:

Terminal
shell
elide --format=json config/config.pkl

Use the output in scripts and CI

Stdout contains only the rendered document; diagnostics and evaluation errors go to stderr. No --quiet flag is needed for redirection or pipelines. For example, inspect a property with jq installed:

Terminal
shell
elide --format=json config.pkl | jq '.port'

An evaluation failure exits with code 1 and writes no rendered content to stdout. To update a file atomically, use --out rather than shell redirection:

Terminal
shell
elide --format=json --out config.json config.pkl

--out config.json writes a temporary file in the destination directory and atomically replaces config.json only after evaluation and writing succeed. Failures leave the existing file unchanged and exit nonzero. The destination directory must exist and support atomic replacement. Relative paths resolve from your working directory.

Use --out - to explicitly select stdout:

Terminal
shell
elide --format=json --out - config.pkl

Document rendering rejects --sandbox and --limit; those execution controls do not apply to this command. For all command options, see the CLI reference. To read a README or runbook in the same terminal, see Markdown in the terminal.

Was this page helpful?