Type Method


Writes a given JSON object to a stream.


+ (NSInteger)writeJSONObject:(id)obj toStream:(NSOutputStream *)stream options:(NSJSONWritingOptions)opt error:(NSError * _Nullable *)error;



The object to write to stream.


The stream to which to write.

The stream should be opened and configured.


Options for writing the JSON data.

See NSJSONWritingOptions for possible values.


If an error occurs, upon return contains an NSError object with code NSPropertyListWriteInvalidError that describes the problem.

Return Value

The number of bytes written to the stream, or 0 if an error occurs.

See Also

Creating JSON Data

+ dataWithJSONObject:options:error:

Returns JSON data from a Foundation object.

+ isValidJSONObject:

Returns a Boolean value that indicates whether a given object can be converted to JSON data.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software