How to Include 'default' Key in YAML Output #259

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

Originally created by @kaniza on GitHub (Dec 25, 2024).

I'm using Pkl version 0.27.1 on macOS.

% pkl --version
Pkl 0.27.1 (macOS 15.1, native)

I want to write Pkl that produces YAML output like the following, but I'm having trouble figuring out how to do it.

list:
  default:
    value: dummy1
  mykey:
    value: dummy2

I understand that when I write Pkl as shown below, 'default' is omitted from the output by specification.

list {
    default {
        value = "dummy1"
    }
    mykey {
        value = "dummy2"
    }
}
$ pkl eval -f yaml sample.pkl

list:
  mykey:
    value: dummy2

So, I tried enclosing 'default' in backticks, but the result remained the same.

list {
    `default` {
        value = "dummy1"
    }
    mykey {
        value = "dummy2"
    }
}
$ pkl eval -f yaml sample.pkl

list:
  mykey:
    value: dummy2

How can I write the Pkl to produce YAML output that includes the 'default' key as shown above?

list:
  default:
    value: dummy1
  mykey:
    value: dummy2
Originally created by @kaniza on GitHub (Dec 25, 2024). I'm using Pkl version 0.27.1 on macOS. ``` % pkl --version Pkl 0.27.1 (macOS 15.1, native) ``` I want to write Pkl that produces YAML output like the following, but I'm having trouble figuring out how to do it. ``` list: default: value: dummy1 mykey: value: dummy2 ``` I understand that when I write Pkl as shown below, 'default' is omitted from the output by specification. ``` sample.pkl list { default { value = "dummy1" } mykey { value = "dummy2" } } ``` ``` $ pkl eval -f yaml sample.pkl list: mykey: value: dummy2 ``` So, I tried enclosing 'default' in backticks, but the result remained the same. ``` sample.pkl list { `default` { value = "dummy1" } mykey { value = "dummy2" } } ``` ``` $ pkl eval -f yaml sample.pkl list: mykey: value: dummy2 ``` How can I write the Pkl to produce YAML output that includes the 'default' key as shown above? ``` list: default: value: dummy1 mykey: value: dummy2 ```
adam closed this issue 2025-12-30 01:22:54 +01:00
Author
Owner

@HT154 commented on GitHub (Dec 25, 2024):

You would need to either a) define a class with a property default or b) use Mapping with key "default". You're (implicitly) using Dynamic here, which has a property default that's marked hidden.

@HT154 commented on GitHub (Dec 25, 2024): You would need to either a) define a class with a property `default` or b) use `Mapping` with key `"default"`. You're (implicitly) using `Dynamic` here, which has a property `default` that's marked `hidden`.
Author
Owner

@kaniza commented on GitHub (Dec 25, 2024):

@HT154 Thank you, I'll try.

@kaniza commented on GitHub (Dec 25, 2024): @HT154 Thank you, I'll try.
Author
Owner

@kaniza commented on GitHub (Dec 25, 2024):

Here's the updated Pkl code that worked:

list = new Mapping {
    ["default"] {
        value = "dummy1"
    }
    ["mykey"] {
        value = "dummy2"	      
    }
}

Using this approach, the "default" key is no longer hidden, and the YAML output is as expected:

list:
  default:
    value: dummy1
  mykey:
    value: dummy2

Thanks for the guidance!

@kaniza commented on GitHub (Dec 25, 2024): Here's the updated Pkl code that worked: ```pkl list = new Mapping { ["default"] { value = "dummy1" } ["mykey"] { value = "dummy2" } } ``` Using this approach, the "default" key is no longer hidden, and the YAML output is as expected: ```yaml list: default: value: dummy1 mykey: value: dummy2 ``` Thanks for the guidance!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#259