Skip to content

How to not render empty properties? #1068

Answered by HT154
adam-long asked this question in Q&A
Discussion options

You must be logged in to vote

The syntax for declaring nullable properties is documented here: https://pkl-lang.org/main/current/language-reference/index.html#nullable-types

Typically, when you declare an enum (well, really a literal string union) type property, you'd typically write it like this:

value: ("a"|"b"|"c")?

For nullable properties, the default value is implicitly null.

Finally, whether or not null values are rendered in the output is a property of the renderer you're using, typically via a property on it called omitNullProperties. For PcfRenderer this defaults to false (so null values are present in the output) but for JsonRenderer and YamlRenderer the default is true. If you care strongly about the output…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@adam-long
Comment options

Answer selected by adam-long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants