title: How to write data to a JSON data file?
body: <p>I am pretty new to Xcode and objective-C, so excuse me if this is incredibly easy. I am working with a a dictionary from a JSON database, and I want to fill in a database element called "age" for a person. The data in the JSON file looks like this:</p>
  
  <p>{</p>
  
  <pre><code>"firstName":"Debra",
  "lastName":"Palmer",
  "middleInitial":"A",
  "firstNameFirst":"Debra A. Palmer",
  "lastNameFirst":"Palmer, Debra A.",
  "age":""
  </code></pre>
  
  <p>}</p>
  
  <p>This is my code:</p>
  
  <pre><code>      for(NSMutableDictionary *person in _contactsArray1)
          {
              if([person[@"firstNameFirst"] isEqual: _fullName] &amp;&amp; [person[@"age"] isEqual: @""])
              {
                  person[@"age"] = _ageString;
                  // send age data to the dictionary, I get an error saying
                  // Error: Expected method to write dictionary element not found on object type of NSDictionary
              }
              else if ([person[@"firstNameFirst"] isEqual: _fullName] &amp;&amp; ![person[@"age"] isEqual: @""])
              {
  
              }
          }
  </code></pre>
  
  <p>This is my code for loading the JSON Data now:</p>
  
  <pre><code>       NSString *filePath1 = [[NSBundle mainBundle] pathForResource:@"contacts" ofType:@"json"];
  
      // Load the file into an NSData object called JSONData
  
      NSError *error1 = nil;
  
      NSMutableData *JSONData1 = [NSMutableData dataWithContentsOfFile:filePath1 options:NSDataReadingMappedIfSafe error:&amp;error1];
  
      // Create an Objective-C object from JSON Data
  
      _contactsArray1 = [NSJSONSerialization
                    JSONObjectWithData:JSONData1
                    options:0
                    error:
  </code></pre>