Nested Mapping #255

Closed
opened 2025-12-30 01:22:49 +01:00 by adam · 2 comments
Owner

Originally created by @jjuliano on GitHub (Nov 28, 2024).

I want to define a nested mapping nestedRecord with the following structure:

  • The outer mapping has String keys (e.g., record1, record2), each representing a record.
  • The value for each key is an inner mapping, which itself maps String attribute names (e.g., attrib1, attrib2, attrib3) to their String values.

For example:

nestedRecord: Mapping<String, Mapping<String, String>>  

With this, nestedRecord might look like:

nestedRecord {
   ["record1"] {
     ["attrib1"] = "attrib1 value"
     ["attrib2"] = "attrib2 value"
     ["attrib3"] = "attrib3 value"
   }

   ["record2"] {
     ["attrib1"] = "attrib1 value"
     ["attrib2"] = "attrib2 value"
     ["attrib3"] = "attrib3 value"
   }
}

I encountered an error while attempting to define a nested mapping:

│ Expected value of type `Mapping`, but got type `String`.
│ Value: "attributes1 value"
│ 
│ 1 | nestedRecord: Mapping<String, Mapping<String, String>>?
│                                 ^^^^^^^^^^^^^^^^^^^^^^^

Does pkl support nested mappings i.e.Mapping<String, Mapping<String, String>>? If so, how should I define this structure correctly?

Originally created by @jjuliano on GitHub (Nov 28, 2024). I want to define a nested mapping `nestedRecord` with the following structure: - The outer mapping has `String` keys (e.g., `record1`, `record2`), each representing a record. - The value for each key is an inner mapping, which itself maps `String` attribute names (e.g., `attrib1`, `attrib2`, `attrib3`) to their `String` values. For example: ``` nestedRecord: Mapping<String, Mapping<String, String>> ``` With this, `nestedRecord` might look like: ``` nestedRecord { ["record1"] { ["attrib1"] = "attrib1 value" ["attrib2"] = "attrib2 value" ["attrib3"] = "attrib3 value" } ["record2"] { ["attrib1"] = "attrib1 value" ["attrib2"] = "attrib2 value" ["attrib3"] = "attrib3 value" } } ``` I encountered an error while attempting to define a nested mapping: ``` │ Expected value of type `Mapping`, but got type `String`. │ Value: "attributes1 value" │ │ 1 | nestedRecord: Mapping<String, Mapping<String, String>>? │ ^^^^^^^^^^^^^^^^^^^^^^^ ``` Does pkl support nested mappings i.e.`Mapping<String, Mapping<String, String>>`? If so, how should I define this structure correctly?
adam closed this issue 2025-12-30 01:22:49 +01:00
Author
Owner

@odenix commented on GitHub (Nov 28, 2024):

It does, and your syntax looks correct to me. I might be able to help if you posted a reproducer.

@odenix commented on GitHub (Nov 28, 2024): It does, and your syntax looks correct to me. I might be able to help if you posted a reproducer.
Author
Owner

@jjuliano commented on GitHub (Nov 29, 2024):

sorry, I made a syntax error, it does work. I have the attributes directly on the nestedRecord. We can close this now.

@jjuliano commented on GitHub (Nov 29, 2024): sorry, I made a syntax error, it does work. I have the attributes directly on the nestedRecord. We can close this now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#255