-
Notifications
You must be signed in to change notification settings - Fork 285
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
Not possible to render mapping with Int keys in YAML #878
Comments
Seems it is not allowed to use numbers only in xml as a tag name. However, you should be able to use |
I actually tried it also for a json and yaml. Output is the same. I need this for yaml file. |
JSON requires string keys. I was less sure about YAML (1.2) and looked up the spec: non-string keys (including seq or map) are explicitly allowed, but many YAML implementations do not support them. This includes Pkl's currently, which I think should be considered a bug. This construct is legal in both Pkl and YAML, so the renderer should accept it (at least for scalar types). If you can accept numeric string keys, as a workaround you may be able to handle this at render time with a converter, e.g.: output {
renderer = new YamlRenderer {
converters {
[Mapping] = (it) -> new Mapping {
for (k, v in it) {
[k.toString()] = v
}
}
}
}
} |
Okay, PR open with the fix. You can also use render directives to get the desired output until this fix is released: output {
renderer = new YamlRenderer {
converters {
[Mapping] = (it) -> new Mapping {
for (k, v in it) {
[if (k is Number || k is Boolean || k is Null) new RenderDirective { text = k.toString() } else k] = v
}
}
}
}
} |
Changing the title (this behavior is correct in XML and JSON). |
when trying to render it, I get an error:
The text was updated successfully, but these errors were encountered: