Not possible to use output keyword even surrounded by backticks #212

Closed
opened 2025-12-30 01:22:17 +01:00 by adam · 2 comments
Owner

Originally created by @dshatokhin on GitHub (Oct 8, 2024).

I'm generating a json output for the object with key name output but even if I enclose it in backticks pkl throws an error:

`output` {
  key = "value"
}
> pkl eval keywords.pkl -f json
–– Pkl Error ––
Cannot find property `key` in object of type `ModuleOutput`.

2 | key = "value"
    ^^^
at keywords#output (file:///home/denis/github/envoy-gateway-vm/private/keywords.pkl, line 2)

Available properties:
files
renderer
text
value

I'm expecting it to work as any other keywords such as class, module, string etc:

> pkl eval keywords.pkl -f json
{
  "class": {
    "key": "value"
  }
}

> pkl eval keywords.pkl -f json
{
  "module": {
    "key": "value"
  }
}

> pkl eval keywords.pkl -f json
{
  "string": {
    "key": "value"
  }
}

Version used Pkl 0.26.3 on amd64 Linux machine

Originally created by @dshatokhin on GitHub (Oct 8, 2024). I'm generating a `json` output for the object with key name `output` but even if I enclose it in backticks `pkl` throws an error: ```pkl `output` { key = "value" } ``` ```plain > pkl eval keywords.pkl -f json –– Pkl Error –– Cannot find property `key` in object of type `ModuleOutput`. 2 | key = "value" ^^^ at keywords#output (file:///home/denis/github/envoy-gateway-vm/private/keywords.pkl, line 2) Available properties: files renderer text value ``` I'm expecting it to work as any other keywords such as `class`, `module`, `string` etc: ```plain > pkl eval keywords.pkl -f json { "class": { "key": "value" } } > pkl eval keywords.pkl -f json { "module": { "key": "value" } } > pkl eval keywords.pkl -f json { "string": { "key": "value" } } ``` Version used `Pkl 0.26.3` on `amd64` Linux machine
adam closed this issue 2025-12-30 01:22:17 +01:00
Author
Owner

@bioball commented on GitHub (Oct 8, 2024):

The output property is a special property on Module, and can only be used to describe the module's output.

To get around this, you'll need to define a class with output as a property, then set your module's output to a value of that class.

class Foo {
  output: Output
}

class Output {
  key: String
}

foo: Foo = new {
  output {
    key = "foo"
  }
}

output {
  value = foo
}

This produces:

output {
  key = "foo"
}
@bioball commented on GitHub (Oct 8, 2024): The `output` property is a special property on `Module`, and can only be used to describe the module's output. To get around this, you'll need to define a class with `output` as a property, then set your module's output to a value of that class. ```pkl class Foo { output: Output } class Output { key: String } foo: Foo = new { output { key = "foo" } } output { value = foo } ``` This produces: ``` output { key = "foo" } ```
Author
Owner

@dshatokhin commented on GitHub (Oct 8, 2024):

@bioball , thanks for such a quick reply, I will then use the workaround you suggested

@dshatokhin commented on GitHub (Oct 8, 2024): @bioball , thanks for such a quick reply, I will then use the workaround you suggested
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#212