apple / apple/pkl

Duplicate Key Issue When Converting pkl to JSON

Open
#36 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11.5k
Forks
402
Avg merge
1d 15h
Merged PRs (30d)
20

Description

### Description
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.

### Steps to Reproduce
Here is the pkl code defining a series of beverages and their ingredients:

```
Tea {
Base = "Black Tea"
}

BubbleTea = (Tea) {
Additives {
"Pearls"
}
}

MilkBubbleTea = (BubbleTea) {
Additives {
"Creamer"
}
}

FreshMilkBubbleTea = (BubbleTea) {
Additives {
"Fresh Milk"
}
}

FreshMilkBubbleTea2 = (MilkBubbleTea) {
["Additives"] {
"Fresh Milk"
}
}
```

### Expected Behavior
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.

### Actual Behavior
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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the supplied pkl beverage definitions and inspect the JSON conversion entry point responsible for FreshMilkBubbleTea2. Done means duplicate keys from inherited or nested entries are detected before invalid JSON is emitted, with the chosen error or warning behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.