title: Structs depending on JSON data
body: <p>I am currently working with a financial market API where I can get JSON data as a single stock ticker/quote or in a batch.</p>
  <p>I am able to decode the JSON data if I know what stock ticker I am trying to request from the API ahead of time.</p>
  <p>What I am struggling with is how to write my <code>structs</code> so that I can decode any stock ticker the user selects.</p>
  <p>For example, in development I know I will want to request stock data on AAPL, so I'll write the appropriate <code>struct</code> (below), but lets say, on actual deployment, I'll want to take a look at TSLA stock data, in such a case, I wouldn't have the appropriate TSLA <code>struct</code> written, because I only have a <code>struct</code> written for AAPL, thus receiving an error.</p>
  <p>Is there any way to write some sort of dynamic <code>struct</code> or use a Swift library that can help solve this problem?</p>
  <p>I will post a snippet of the JSON data and my <code>struct</code> below.</p>
  <pre><code>{&quot;AAPL&quot;:
      {&quot;quote&quot;:
          {&quot;symbol&quot;:&quot;AAPL&quot;,
              &quot;companyName&quot;:&quot;Apple, Inc.&quot;,
              &quot;primaryExchange&quot;:&quot;NASDAQ&quot;,
              &quot;calculationPrice&quot;:&quot;close&quot;,
              &quot;open&quot;:112.67,
              &quot;openTime&quot;:1600781401038,
              &quot;openSource&quot;:&quot;official&quot;,
              &quot;close&quot;:111.81,
              &quot;closeTime&quot;:1600804800589,
              &quot;closeSource&quot;:&quot;official&quot;,
              &quot;high&quot;:112.86,
              &quot;highTime&quot;:1600819199980,
              &quot;highSource&quot;:&quot;15 minute delayed price&quot;,
              &quot;low&quot;:109.16,
              &quot;lowTime&quot;:1600786957213,
              &quot;lowSource&quot;:&quot;15 minute delayed price&quot;,
              &quot;latestPrice&quot;:111.81,
              &quot;latestSource&quot;:&quot;Close&quot;,
              &quot;latestTime&quot;:&quot;September 22, 2020&quot;,
              &quot;latestUpdate&quot;:1600804800589,
              &quot;latestVolume&quot;:183055373,
              &quot;iexRealtimePrice&quot;:111.545,
              &quot;iexRealtimeSize&quot;:56,
              &quot;iexLastUpdated&quot;:1600806216383,
              &quot;delayedPrice&quot;:110.6,
              &quot;delayedPriceTime&quot;:1600819199980,
              &quot;oddLotDelayedPrice&quot;:127.67,
              &quot;oddLotDelayedPriceTime&quot;:1600807552123,
              &quot;extendedPrice&quot;:110.6,
              &quot;extendedChange&quot;:-1.21,
              &quot;extendedChangePercent&quot;:-0.01082,
              &quot;extendedPriceTime&quot;:1600819199980,
              &quot;previousClose&quot;:110.08,
              &quot;previousVolume&quot;:195713815,
              &quot;change&quot;:1.73,
              &quot;changePercent&quot;:0.01572,
              &quot;volume&quot;:183055373,
              &quot;iexMarketPercent&quot;:0.007153872636301017,
              &quot;iexVolume&quot;:1303096,
              &quot;avgTotalVolume&quot;:196415720,
              &quot;iexBidPrice&quot;:0,
              &quot;iexBidSize&quot;:0,
              &quot;iexAskPrice&quot;:0,
              &quot;iexAskSize&quot;:0,
              &quot;iexOpen&quot;:null,
              &quot;iexOpenTime&quot;:null,
              &quot;iexClose&quot;:111.8,
              &quot;iexCloseTime&quot;:1600804792007,
              &quot;marketCap&quot;:1938483513000,
              &quot;peRatio&quot;:33.69,
              &quot;week52High&quot;:137.98,
              &quot;week52Low&quot;:53.15,
              &quot;ytdChange&quot;:0.50212,
              &quot;lastTradeTime&quot;:1600804799962,
              &quot;isUSMarketOpen&quot;:false
          }
      },
      &quot;FB&quot;:
      {&quot;quote&quot;:
          {&quot;symbol&quot;:&quot;FB&quot;,
              &quot;companyName&quot;:&quot;Facebook, Inc.&quot;,
              &quot;primaryExchange&quot;:&quot;NASDAQ&quot;,
              &quot;calculationPrice&quot;:&quot;close&quot;,
              &quot;open&quot;:253.31,
              &quot;openTime&quot;:1600781400128,
              &quot;openSource&quot;:&quot;official&quot;,
              &quot;close&quot;:254.75,
              &quot;closeTime&quot;:1600804800789,
              &quot;closeSource&quot;:&quot;official&quot;,
              &quot;high&quot;:255.32,
              &quot;highTime&quot;:1600819191691,
              &quot;highSource&quot;:&quot;15 minute delayed price&quot;,
              &quot;low&quot;:248.22,
              &quot;lowTime&quot;:1600787261157,
              &quot;lowSource&quot;:&quot;15 minute delayed price&quot;,
              &quot;latestPrice&quot;:254.75,
              &quot;latestSource&quot;:&quot;Close&quot;,
              &quot;latestTime&quot;:&quot;September 22, 2020&quot;,
              &quot;latestUpdate&quot;:1600804800789,
              &quot;latestVolume&quot;:30401995,
              &quot;iexRealtimePrice&quot;:254.695,
              &quot;iexRealtimeSize&quot;:100,
              &quot;iexLastUpdated&quot;:1600804797803,
              &quot;delayedPrice&quot;:253.8,
              &quot;delayedPriceTime&quot;:1600819191691,
              &quot;oddLotDelayedPrice&quot;:254.74,
              &quot;oddLotDelayedPriceTime&quot;:1600804799413,
              &quot;extendedPrice&quot;:253.8,
              &quot;extendedChange&quot;:-0.95,
              &quot;extendedChangePercent&quot;:-0.00373,
              &quot;extendedPriceTime&quot;:1600819191691,
              &quot;previousClose&quot;:248.15,
              &quot;previousVolume&quot;:24709378,
              &quot;change&quot;:6.6,
              &quot;changePercent&quot;:0.0266,
              &quot;volume&quot;:30401995,
              &quot;iexMarketPercent&quot;:0.025296103101128724,
              &quot;iexVolume&quot;:769052,
              &quot;avgTotalVolume&quot;:25154911,
              &quot;iexBidPrice&quot;:0,
              &quot;iexBidSize&quot;:0,
              &quot;iexAskPrice&quot;:0,
              &quot;iexAskSize&quot;:0,
              &quot;iexOpen&quot;:null,
              &quot;iexOpenTime&quot;:null,
              &quot;iexClose&quot;:254.695,
              &quot;iexCloseTime&quot;:1600804797803,
              &quot;marketCap&quot;:725735292113,
              &quot;peRatio&quot;:30.89,
              &quot;week52High&quot;:304.67,
              &quot;week52Low&quot;:137.1,
              &quot;ytdChange&quot;:0.241301,
              &quot;lastTradeTime&quot;:1600804800789,
              &quot;isUSMarketOpen&quot;:false}
      }
  }
  
  ----
  
  struct iexTicker: Decodable {
      let AAPL: iexQuote
      let FB: iexQuote
  }
  
  struct iexQuote: Decodable {
      let quote: iexData
  }
     
  struct iexData: Decodable {
      let symbol: String?
      let companyName: String?
      let primaryExchange: String?
      let calculationPrice: String?
      let open: Double?
      let openTime: Double?
      let openSource: String?
      let close: Double?
      let closeTime: Double?
      let closeSource: String?
      let high: Double?
      let highTime: Double?
      let low: Double?
      let lowTime: Double?
      let lowSource: String?
      let latestPrice: Double?
      let latestSource: String?
      let latestTime: String?
      let latestUpdate: Double?
      let latestVolume: Double?
      let iexRealtimePrice: Double?
      let iexRealtimeSize: Double?
      let iexLastUpdated: Double?
      let delayedPrice: Double?
      let delayedPriceTime: Double?
      let oddLotDelayedPrice: Double?
      let oddLotDelayedPriceTime: Double?
      let extendedPrice: Double?
      let extendedChange: Double?
      let extendedChangePercent: Double?
      let extendedPriceTime: Double?
      let previousClose: Double?
      let previousVolume: Double?
      let change: Double?
      let changePercent: Double?
      let volume: Double?
      let iexMarketPercent: Double?
      let iexVolume: Double?
      let avgTotalVolume: Double?
      let iexBidPrice: Double?
      let iexBidSize: Double?
      let iexAskPrice: Double?
      let iexAskSize: Double?
      let iexOpen: Double?
      let iexOpenTime: Double?
      let iexClose: Double?
      let iexCloseTime: Double?
      let marketCap: Double?
      let peRatio: Double?
      let week52High: Double?
      let week52Low: Double?
      let ytdChange: Double?
      let lastTradeTime: Double?
      let isUSMarketOpen: Bool?
  }
  </code></pre>