title: How can I display the key names in a JSON file as labels with Swift
body: <p>I am new to Swift and iOS development. I would appreciate some guidance on how to display the key names in a JSON file as labels.</p>
  
  <p>Using Swift 5 and the following JSON data (this is a snippet of a larger file):</p>
  
  <pre><code>{
    "color": {
        "white": { "value": "#fff" },
        "black": { "value": "#000" },
        "gray": {
          "10": { "value": "#f5f7f8" },
          "20": { "value": "#e8eced" },
          "30": { "value": "#d5d9db" },
          "40": { "value": "#b6bec2" },
          "50": { "value": "#8e999e" },
          "60": { "value": "#69757a" },
          "70": { "value": "#495257" },
          "80": { "value": "#333a3d" },
          "90": { "value": "#1f2426" }
     }
  </code></pre>
  
  <p>... I need create a grid that displays the color name (the key) as a label and the actual color next to it ... something like this:</p>
  
  <pre><code>White:  (display a white rectangle)
  Black:  (display a black rectangle)
  Gray10: (display a gray rectangle)
  Gray20: (display a darker gray rectangle)
  Gray30: (display a darker gray rectangle)
  ...
  ...
  Gray90: (display a very dark gray rectangle)
  </code></pre>
  
  <p>I am able to parse/decode and iterate though the JSON file using Swift to <code>print()</code> the color hex values.</p>
  
  <p>What I cannot figure out is how to display the actual key names (the color names) as labels.</p>
  
  <p>Here's what I have working in my playground so far. I have not figured out how to processes the nested "Gray" color values yet, so I excluded them from my code.</p>
  
  <p>It does print out the color hex values. I commented out the code to print the <code>key</code> because it does not work.</p>
  
  <pre><code>import Foundation
  
  let json = """
  {
    "color": {
      "white": { "value": "#fff" },
      "black": { "value": "#000" }
    }
  }
  """.data(using: .utf8)!
  
  struct color: Codable {
  //  let key: String
      let value: String
  }
  
  struct Entry: Codable {
      let color: [String: color]
  }
  
  let jsonDecoder = JSONDecoder()
  
  do {
    let parsedJSON = try jsonDecoder.decode(Entry.self, from: json)
    for color in parsedJSON.color {
  //  print(color.value.key)
      print(color.value.value)
    }
  }
  
  
  Thanks!
  </code></pre>