title: Create an object from JSON response, modify values, and return it in Swift
body: <p>In an app I recently developed, the client wanted to be able to create a NEW user in their POS system. Their POS system is web-based and has a massive API, so this was easy.</p>
  
  <p>Now they want the app to see if the user exists before creating a duplicate user, which is fine. However, they also want to update the information in the user record if it is a duplicate.</p>
  
  <p>The POS system's API returns an extensive "Customer" JSON response with 250+ fields. I only need to update 4 of those fields.</p>
  
  <p>Is there a way to easily create an object from the "Get Customer" response (it is a multi-dimensional array), edit specific values, and then post that object back as JSON to the "Update Customer" method?</p>
  
  <p><strong><em>Edit #1</em></strong></p>
  
  <p>Still having problems wrapping my head around this. To further clarify the process and how it works:</p>
  
  <p><code>1) API call to get user information
   2) User information returned via JSON. The response is a REALLY big, multi-dimensional, response.
   3) 4 of the fields in the returned JSON customer have to be edited
   4) JSON then needs to be used to create "Parameters" to PUT/POST back to the API.
  </code></p>
  
  <p>Here's what I've done so far:</p>
  
  <pre><code>var existingCustomer = NSMutableDictionary()
  
  ...Function to acquire JSON using Alamofire...
  
  var json = JSON(response!)
  let d = json["Customer"]["Customer"].dictionaryValue
  
  for (k, v) in d {
      if let value = v.string {
          self.existingCustomer[k] = value
      }
      //CHECK FOR OTHER TYPES
  }
  </code></pre>
  
  <p>This works to make the dictionary look similar to the JSON, however I am concerned about the multi-dimensional aspect of the Customer JSON. I am not sure that <code>value</code>, once checked for being a <code>dictionaryObject</code> will be keep it's K,V relationship. I haven't tested yet though.</p>
  
  <p>Once I get the <code>existingCustomer</code> Dictionary complete, I can then iterate through the entries to create the params to POST/PUT, however, again, they need to retain their KV relationship.</p>
  
  <p>The params generally look like:</p>
  
  <pre><code>var params = [
      "firstName":"John",
      "lastName":"Appleseed",
      "photos": [
          "url":"www.website.com",
          "width":1024,
          "height":768
      ],
      "addresses": [
          "shippingAddress": [
              "street":"123 Test Road"
          ],
          "homeAddress": [
              "street":"456 Test Crescent"
          ]
      ],
      "phone":"555-555-5555"
  ]
  </code></pre>
  
  <p>Only much, much longer. There's something like 200 KVs</p>