JSON to Objective-C Converter

Objective-C model classes from a JSON sample

Input

Output

Paste your JSON on the left and the Objective-C code shows up here.

Or drop a file on this box, , or .

What does the JSON to Objective-C converter generate?

NSJSONSerialization hands you nested NSDictionary and NSArray objects, and most Objective-C codebases wrap those in model classes so the rest of the app can use real properties. Give this page one sample payload and it writes those classes for you: @class forward declarations, one @interface ... : NSObject per JSON object inside NS_ASSUME_NONNULL_BEGIN/END, and a matching @implementation with an initWithDictionary: that copies each value across.

Property attributes follow the usual rules: assign for scalars (NSInteger, double, BOOL), copy for NSString, NSArray and NSDictionary, strong for nested model objects, and nullable for anything that was null or missing in the sample. A number that can be null becomes NSNumber *, since a scalar can't hold nil. Arrays are typed with lightweight generics (NSArray<Device *> *), and arrays of objects are turned into model instances by a small helper function.

JSON null arrives from NSJSONSerialization as NSNull; the generated code treats it like a missing key, so you get nil or 0 instead of a crash. Property names are camelCase, and names that would clash with NSObject or ARC conventions, such as description, hash, id or anything starting with new or copy, get a Value suffix. There's no NSCoding or NSSecureCoding support; add it if you archive these objects. Everything runs in your browser.

How to use it

Paste JSON and the classes appear as you type.

1

Paste a JSON sample

Put the payload in the Input panel (type it, paste it, or use Upload for a .json or .txt), or hit Sample. A track record from a music app makes a good first try:

{"trackId":981,"title":"Night Ferry","artist":"Ingrid Sol","durationMs":214000,"downloadable":false}

Class Name names the root class; call it Track for the record above and you get NSInteger trackId, NSString *title and BOOL downloadable. When the output panel reports invalid JSON, the JSON Validator will point at the offending line.

2

Read the interface and implementation

The Output panel shows the interfaces first, then the implementation section. Split it into a .h and a .m at the #pragma mark line if you prefer separate files.

3

Copy or download

Copy the code or Download a .m file, then create the root object with [[RootObject alloc] initWithDictionary:json].

Where this saves time

Maintaining an older iOS app

A new endpoint shows up in an app that is still mostly Objective-C. Paste the response and get models that match the house style instead of passing dictionaries around.

Replacing stringly-typed dictionary access

Code full of dict[@"subscriberId"] is easy to break with a typo. Generated properties give you autocomplete and compiler checks.

Bridging to Swift

The nullability annotations and generics carry over when Swift code imports the header, so the models show up as properly optional Swift types.

Prototyping a payload

Paste a sample from the backend team and you get a quick view of how many classes and properties the client side will need.

Common Questions

Does the output include parsing code?

Yes, a simple one: each class has initWithDictionary:, which reads the NSDictionary from NSJSONSerialization, maps nested dictionaries and arrays of dictionaries into model objects, and treats NSNull as nil. It doesn't validate types, so a string where a number was expected is stored as is.

Has it been compiled?

We syntax-check the output with clang under ARC against a minimal stand-in for Foundation, not Apple's SDK. Build it in Xcode before relying on it and review fields typed id, which mean the sample was null or mixed.

Why is a property called descriptionValue?

A property named description or hash would override NSObject methods, and ARC treats getters starting with new, copy, alloc or init as returning owned objects. Those names get a Value suffix; the dictionary key used in initWithDictionary: stays the original.

How are large integers handled?

Values that fit in 64 bits become NSInteger (64-bit on all current Apple platforms), larger positive ones unsigned long long, and anything bigger is kept as NSNumber *. Nullable numbers are always NSNumber *.

Is my JSON uploaded?

No. The header and implementation are written by code running in this tab, so the payload never reaches a server. Anything over 256 KB is refused; the classes only need one representative object, so cut long arrays down to two or three items first.

Other JSON Tools You Might Need

Moving the same models to Swift, or need to clean up the JSON first?