title: Serialize JSON without wrapping in [ ]
body: <p>I am trying to make an HTTP PUT request to a CouchDB server. I am converting an NSString instance to NSData. I then convert this NSData instance to an NSArray and attempt to PUT this to CouchDB. So something like this:</p>
  
  <pre><code>//convert string to NSData
      NSData *docData = [@"{\"name\":\"nick\"}" dataUsingEncoding:NSUTF8StringEncoding];
  //NSData to NSArray
      NSArray *arrayJson = [NSArray arrayWithObjects:[NSJSONSerialization JSONObjectWithData:docData options:kNilOptions error:nil],nil];
  </code></pre>
  
  <p>I am then creating an HTTP PUT request using <a href="https://github.com/AFNetworking/AFNetworking" rel="nofollow">AFNetworking</a> (which is rad btw ;)) </p>
  
  <p>The problem is that this creates a json string which looks like:</p>
  
  <pre><code>[{"name":"nick"}]
  </code></pre>
  
  <p>This is valid JSON but Couch complains with 400 Bad JSON. Removing the [ ]s fixes the problem. I'm sure these brackets are the result of converting NSData to NSArray but I'm not sure how else to accomplish this using NSJSONSerialization. Can anyone help? </p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>For clarity sake let me explain the problem I was having further. I am creating a document using the CouchDB HTTP API using a PUT HTTP request. The document could be hand coded JSON and that is why I have this parsing challenge. Couch expects a single document to create. Therefore it expects a single JSON object. NOT an array of them. That seems to be why [{"key":"value"}] returns a 400 HTTP response from Couch. Even if the array contains a single object. Seems a bit picky that the API wouldn't just infer correctly based on the array length.. but I guess you could argue either way. See the selected answer below. This is what I was looking for. Thanks to all those who responded!   </p>