title: Removing nulls from a JSON structure recursively
body: <p>I'm frequently finding the need to cache data structures created by <code>NSJSONSerialization</code> to disk and as <code>-writeToFile</code> fails if there are nulls, I need a fix that works when the structure is unknown.
  This works, and direct mutation is allowed as the instances of NSMutableDictionary themselves are not being enumerated, but it feels a bit hacky.</p>
  
  <p>Is this totally fine or is it absolutely necessary to recreate a new tree and return that?</p>
  
  <pre><code>- (void) removeNullsFromJSONTree:(id) branch
  {
      if ([branch isKindOfClass:[NSMutableArray class]])
      {
          //Keep drilling to find the leaf dictionaries
          for (id childBranch in branch)
          {
              [self removeNullsFromJSONTree:childBranch];
          }
      }
      else if ([branch isKindOfClass:[NSMutableDictionary class]])
      {
          const id nul = [NSNull null];
          const NSString *empty = @"";
          for(NSString *key in [branch allKeys])
          {
              const id object = [branch objectForKey:key];
              if(object == nul)
              {
                  [branch setObject:empty forKey:key];
              }
          }
      }
  }
  </code></pre>