title: Encoding string data back to JSON is giving an error
body: <p>I've removed <code>jsonCallback (</code> and <code>)</code> from the URL <a href="https://www.apple.com/support/systemstatus/data/developer/system_status_en_US.js" rel="nofollow noreferrer">https://www.apple.com/support/systemstatus/data/developer/system_status_en_US.js</a> using the below.</p>
  <pre><code>        var dataString = String(data: data, encoding: .utf8)
          dataString = dataString?.replacingOccurrences(of: &quot;jsonCallback(&quot;, with: &quot;&quot;)
          dataString = dataString?.replacingOccurrences(of: &quot;);&quot;, with: &quot;&quot;)
          let json = dataString?.data(using: .utf8)
          let jsonData = try JSONEncoder().encode(json)
  </code></pre>
  <p>The error I'm getting back</p>
  <pre><code>typeMismatch(Swift.Dictionary&lt;Swift.String, Any&gt;, Swift.DecodingError.Context(codingPath: [], debugDescription: &quot;Expected to decode Dictionary&lt;String, Any&gt; but found a string/data instead.&quot;, underlyingError: nil))
  </code></pre>
  <p>I can't find where the mismatch is happening at because when I look at <code>dataString</code> and piece it back together the JSON decoding model appears to match.</p>
  <p>Here's the full code:</p>
  <pre><code> func fetchSystemStatus() async -&gt; [SystemStatus] {
          guard let url = URL(string: systemStatusURL) else {
              return []
          }
  
          do {
              let (data, response) = try await URLSession.shared.data(from: url)
  
              // This is commented out data to try and gather developer system status
              var dataString = String(data: data, encoding: .utf8)
              dataString = dataString?.replacingOccurrences(of: &quot;jsonCallback(&quot;, with: &quot;&quot;)
              dataString = dataString?.replacingOccurrences(of: &quot;);&quot;, with: &quot;&quot;)
              let json = dataString?.data(using: .utf8)
              let jsonData = try JSONEncoder().encode(json)
  
              guard (response as? HTTPURLResponse)?.statusCode == 200 else {
                  print(&quot;\(#function) \(response)&quot;)
                  return []
              }
  
              let statusData = try JSONDecoder().decode(SystemStatus.self, from: jsonData)
              return [statusData]
          } catch {
              print(&quot;\(#function) \(error)&quot;)
              return []
          }
      }
  </code></pre>
  <p>Model:</p>
  <pre><code>// MARK: - SystemStatus
  struct SystemStatus: Codable {
      let services: [Service]
  
      enum CodingKeys: String, CodingKey {
          case services = &quot;services&quot;
      }
  }
  
  // MARK: - Service
  struct Service: Codable, Identifiable {
      let id = UUID()
      let redirectURL: String?
      let events: [Event]
      let serviceName: String
  
      enum CodingKeys: String, CodingKey {
          case redirectURL = &quot;redirectUrl&quot;
          case events = &quot;events&quot;
          case serviceName = &quot;serviceName&quot;
      }
  }
  
  // MARK: - Event
  struct Event: Codable {
      let usersAffected: String
      let epochStartDate: Int
      let epochEndDate: Int
      let messageID: String
      let statusType: String
      let datePosted: String
      let startDate: String
      let endDate: String
      let affectedServices: [String]?
      let eventStatus: String
      let message: String
  
      enum CodingKeys: String, CodingKey {
          case usersAffected = &quot;usersAffected&quot;
          case epochStartDate = &quot;epochStartDate&quot;
          case epochEndDate = &quot;epochEndDate&quot;
          case messageID = &quot;messageId&quot;
          case statusType = &quot;statusType&quot;
          case datePosted = &quot;datePosted&quot;
          case startDate = &quot;startDate&quot;
          case endDate = &quot;endDate&quot;
          case affectedServices = &quot;affectedServices&quot;
          case eventStatus = &quot;eventStatus&quot;
          case message = &quot;message&quot;
      }
  }
  </code></pre>