Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kaniza opened this issue Dec 25, 2024 · 3 comments
Closed

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

kaniza opened this issue Dec 25, 2024 · 3 comments

Comments

@kaniza
Copy link

kaniza commented 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
@HT154
Copy link
Contributor

HT154 commented 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.

@kaniza
Copy link
Author

kaniza commented Dec 25, 2024

@HT154 Thank you, I'll try.

@kaniza
Copy link
Author

kaniza commented 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 kaniza closed this as completed Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants