When using pkl for object definitions and converting them to JSON format, I encountered an issue where duplicating nested object entries with the same entry names results in generated JSON with duplicate keys, violating JSON standards.
Tea {
Base = "Black Tea"
}
BubbleTea = (Tea) {
Additives {
"Pearls"
}
}
MilkBubbleTea = (BubbleTea) {
Additives {
"Creamer"
}
}
FreshMilkBubbleTea = (BubbleTea) {
Additives {
"Fresh Milk"
}
}
FreshMilkBubbleTea2 = (MilkBubbleTea) {
["Additives"] {
"Fresh Milk"
}
}
When converting to JSON, the process should detect potential duplicate keys resulting from nested object entries with the same name and either halt with an error or provide a warning. This behavior would prevent the generation of invalid JSON formats and ensure data integrity, especially in scenarios involving object inheritance and overriding.
The generated JSON for the FreshMilkBubbleTea2 object includes duplicate Additives keys, as shown below:
{
"Tea": {
"Base": "Black Tea"
},
"BubbleTea": {
"Base": "Black Tea",
"Additives": [
"Pearls"
]
},
"MilkBubbleTea": {
"Base": "Black Tea",
"Additives": [
"Pearls",
"Creamer"
]
},
"FreshMilkBubbleTea": {
"Base": "Black Tea",
"Additives": [
"Pearls",
"Fresh Milk"
]
},
"FreshMilkBubbleTea2": {
"Base": "Black Tea",
"Additives": [
"Pearls",
"Creamer"
],
"Additives": [
"Fresh Milk"
]
}
}
This results in an invalid JSON format since JSON does not allow duplicate keys at the same level.