title: Stringified JSON to Swift Object or JSON dictionary
body: <p>In my Swift code I make a <code>URLRequest</code> to my node.js server:</p>
  
  <pre><code>URLSession.shared.dataTask(with: checkoutRequest, completionHandler: {
      [weak self] (data: Data?, response: URLResponse?, error: Error?) in
      guard let data = data,
          let dataString = String(data: data, encoding: String.Encoding.utf8) else {
              return
      }
  
      // Help me!!!
  
  }).resume()
  </code></pre>
  
  <p>The node.js handles this request by processing a transaction through the Braintree Payments checkout API. </p>
  
  <pre><code>checkoutProcessor.processCheckout(amount, nonce, (error, result) =&gt; {
      // Checkout callback
      if (error) {
          res.write(error.message)
          res.end()
      } else if (result) {
          console.log(result)
          res.write(JSON.stringify(result))
          res.end()
      }
  })
  </code></pre>
  
  <p>As usual, if the API request fails (e.g., no signal) it returns an <code>error</code> but if the transaction <em>goes through</em>, it returns a <code>result</code>. </p>
  
  <p>The type of the <code>result</code>, however, depends on whether the <em>financial transaction</em> fails or succeeds: </p>
  
  <p>For example, the <code>result</code> for a successful transaction:</p>
  
  <pre><code>Object {transaction: Transaction, success: true}
  </code></pre>
  
  <p><code>result</code> for failed transaction:</p>
  
  <pre><code>ErrorResponse {errors: ValidationErrorsCollection, params: Object, message: "Insufficient Funds", transaction: Transaction, success: false}
  </code></pre>
  
  <p>The <code>dataString</code> winds up looking like this:</p>
  
  <p>{\"transaction\":{\"id\":\"m7mj3qd7\",\"status\":\"submitted_for_settlement\",\"type\":\"sale\",\"currencyIsoCode\":\"USD\",\"amount\":\"12.34\",\"merchantAccountId\":\"yourpianobar\",\"subMerchantAccountId\":null,\"masterMerchantAccountId\":null,\"orderId\":null,\"createdAt\":\"2018-09-19T03:30:27Z\",\"updatedAt\":\"2018-09-19T03:30:27Z\",\"customer\":{\"id\":\"622865439\",\"firstName\":\"Test\",\"lastName\":\"FromSwiftTest\"</p>
  
  <p>which certainly resembles a JSON object but I can't seem to decode it with <code>JSONDecoder</code>, doing so fails. (<code>JSONEncoder</code> also fails)</p>
  
  <p>Most solutions I see for <code>Object</code>ifying stringified JSON data into Swift involves writing a swift <code>struct</code> into which to plop all the JSON object's properties, but since this the data structure of the result is unknown on the swift end, I don't know what to do.</p>
  
  <p>How do I get these objects into my swift code? </p>
  
  <p>Note: I've also tried just sending <code>res.send(result)</code> in the node.js code but that doesn't really change anything.</p>