Originally created by @artemijan on GitHub (Jan 10, 2025).
ll = new Mapping<Int, String>{
[1] = ""
}
when trying to render it, I get an error:
–– Pkl Error ––
Cannot render object with non-string key as XML.
Object: new Mapping { [1] = "" }
Key : 1
Originally created by @artemijan on GitHub (Jan 10, 2025).
```
ll = new Mapping<Int, String>{
[1] = ""
}
```
when trying to render it, I get an error:
```
–– Pkl Error ––
Cannot render object with non-string key as XML.
Object: new Mapping { [1] = "" }
Key : 1
```
However, you should be able to use _1 or a1... Which is, in return, in pkl a string 🙃
@StefMa commented on GitHub (Jan 10, 2025):
Seems it is not allowed to use **numbers only** in xml as a tag name.
See also https://www.w3.org/TR/xml/#NT-Name
However, you should be able to use `_1` or `a1`... Which is, in return, in pkl a string 🙃
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
}
}
}
}
}
@HT154 commented on GitHub (Jan 10, 2025):
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.:
```pkl
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
}
}
}
}
}
@HT154 commented on GitHub (Jan 10, 2025):
Okay, PR open with the fix. You can also use render directives to get the desired output until this fix is released:
```pkl
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
}
}
}
}
}
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @artemijan on GitHub (Jan 10, 2025).
when trying to render it, I get an error:
@StefMa commented on GitHub (Jan 10, 2025):
Seems it is not allowed to use numbers only in xml as a tag name.
See also https://www.w3.org/TR/xml/#NT-Name
However, you should be able to use
_1ora1... Which is, in return, in pkl a string 🙃@artemijan commented on GitHub (Jan 10, 2025):
I actually tried it also for a json and yaml. Output is the same. I need this for yaml file.
@HT154 commented on GitHub (Jan 10, 2025):
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.:
@HT154 commented on GitHub (Jan 10, 2025):
Okay, PR open with the fix. You can also use render directives to get the desired output until this fix is released:
@bioball commented on GitHub (Jan 11, 2025):
Changing the title (this behavior is correct in XML and JSON).