NSJSONSerialization thread safety

Does anyone know if NSJSONSerialization is thread safe? Specifically, can I call JSONObjectWithData() concurrently from multiple background threads? The class docs don't mention anything about it:

https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/


Nor does the threading summary page:


https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html


Thanks!

Greg

Answered by Documentation Engineer in 28584022

Yes, NSJSONSerialization itself is thread safe. Calling it from multiple threads is fine (with the obvious exception that you can't do something like call it passing a mutable data and then mutate that data simultaneously).


It would be great if you could write up a bug report for our documentation to get that clarified in the Thread Safety section.

Accepted Answer

Yes, NSJSONSerialization itself is thread safe. Calling it from multiple threads is fine (with the obvious exception that you can't do something like call it passing a mutable data and then mutate that data simultaneously).


It would be great if you could write up a bug report for our documentation to get that clarified in the Thread Safety section.

Will do. Thanks for your help!

My pleasure, thanks for the question. 🙂 If you wouldn't mind posting the bug number here I'd like to keep an eye on it.

NSJSONSerialization thread safety
 
 
Q