CalcCafe

JSON to Objective-C

Paste JSON and instantly get Objective-C class interfaces with inferred property types and memory attributes.

Example

Given this JSON:

{"id": 1, "name": "Ada", "tags": ["math"]}

the tool emits:

#import <Foundation/Foundation.h>

@interface Root : NSObject
@property (nonatomic, assign) NSInteger id;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) NSArray<NSString *> *tags;
@end

Integers map to NSInteger, strings to copy-qualified NSString, and the array becomes a typed NSArray.

How it works

It parses your JSON, infers a Foundation type for every value, and emits an @interface (named Root for the top level) with separate classes generated for each nested object. Conversion runs live as you type.

Good to know

JSON to Objective-C turns a sample JSON payload into ready-to-paste Foundation class declarations, generating an @interface for the top-level object plus a separate class for every nested object it encounters. It is aimed at iOS and macOS developers who are wiring up a REST API response into model objects and want a fast starting point for the header file instead of hand-typing each @property line.

Reach for it whenever you have a real API response handy and need scaffolding for an Objective-C model layer, when you are porting an existing JSON contract into a legacy Objective-C codebase, or when you want a quick visual map of how a payload's shape will translate into classes, types, and memory qualifiers. Conversion runs live in your browser as you type, so you can paste, tweak, and re-copy without round-tripping to a server.

Read the output top-down: the first class is always Root (the outermost object), and each child class is named after the key that holds it. Pay attention to the qualifiers because they encode the tool's type inference: copy means a string, strong means an object pointer or array, and assign means a scalar such as NSInteger, double, or BOOL. A typed NSArray<Type *> tells you the element type was inferred from the first item in the list.

One caveat worth knowing: inference is based purely on the values present in your sample, so a null becomes id, an empty array becomes an untyped NSArray *, and a whole number like 5.0 that arrives without a decimal will be typed as NSInteger rather than double. Feed it a representative payload with non-empty, non-null fields, then review and adjust any property where the JSON sample did not capture the full range of possible values.

Frequently asked questions

How are nested objects and arrays handled?
Each nested JSON object becomes its own @interface class, named after the key that holds it. Arrays become typed NSArray<...> using the inferred type of the first element, so a list of objects yields NSArray and a list of strings yields NSArray.
How does it choose memory attributes and number types?
NSString properties use copy, other object pointers use strong, and primitives (BOOL, NSInteger, double) use assign. Whole numbers become NSInteger, numbers with a fraction become double, booleans become BOOL, and null becomes id.
Is my data uploaded anywhere?
No — it runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

Does this generate the .m implementation file too?
No, it produces only the .h interface declarations with @property lines and @interface/@end blocks. You would add the corresponding @implementation in a .m file yourself, or rely on a runtime mapping library to populate the properties.
Why are integer array elements shown as NSNumber instead of NSInteger?
Objective-C collections like NSArray can only hold object pointers, not raw scalars. The tool wraps primitive array elements as NSNumber so the generated NSArray<NSNumber *> type is valid.
How do I parse JSON into these classes at runtime in Objective-C?
You can use NSJSONSerialization to turn the data into NSDictionary/NSArray, then assign values to your properties manually, or use a mapping framework such as Mantle or JSONModel that maps dictionary keys to declared properties.
What is the difference between copy and strong for these properties?
copy creates an independent copy on assignment and is the convention for NSString to guard against a mutable subclass being passed in, while strong keeps a reference to the same object. The tool uses copy for strings and strong for other object pointers.
Why does the tool use NSInteger instead of int for numbers?
NSInteger is the Foundation type that automatically sizes to the platform's word width (32-bit or 64-bit), which is the standard convention in Cocoa and Cocoa Touch code for whole-number properties.
Can it handle a JSON payload whose top level is an array?
Yes. If the array contains objects, it builds a Root class from the first element and notes the payload is an array of Root objects; if it contains scalars, it emits a typedef for the array type instead.
Should I use Objective-C or Swift for new model objects?
Both are supported for Apple platform development; Swift is Apple's newer primary language with Codable for JSON, while Objective-C remains common in older or mixed codebases. The right choice depends on your project's existing code and constraints.
Is property naming adjusted, for example for keys that aren't valid identifiers?
Class names are sanitized into CamelCase identifiers, but property names are emitted from the JSON keys, so keys with characters that are invalid in Objective-C identifiers may need manual cleanup after generation.

Related tools