JSON Formatter
Format JSON online: beautify messy JSON with 2 or 4 spaces or tabs, sort keys, minify it to one line and find errors. Free, runs in your browser.
Turn JSON into Swift Codable structs or classes, with CodingKeys for snake_case keys. Free JSON to Swift converter for iOS and macOS apps.
Runs in your browser. Your data never leaves your device.
Paste JSON from your API and get Swift types that conform to Codable, ready for JSONDecoder. Nested objects become their own type, arrays become [Type], and when a JSON key is not a good Swift name (snake_case or dashes) the converter writes CodingKeys so the original key is kept. Choose struct or final class, make every property optional, and use var instead of let if you need to change values.
Swift reads JSON with Codable: decode Data into your type with JSONDecoder, and encode it back with JSONEncoder. With URLSession and async/await it takes a few lines.
struct User: Codable {
let id: Int
let name: String
let email: String?
}
let url = URL(string: "https://api.example.com/users/1")!
let (data, _) = try await URLSession.shared.data(from: url)
let user = try JSONDecoder().decode(User.self, from: data) To pass JSON data in a POST request, encode your value, put it in httpBody and set the Content-Type header to application/json.
var request = URLRequest(url: URL(string: "https://api.example.com/users")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONEncoder().encode(user)
let (data, response) = try await URLSession.shared.data(for: request) JSONEncoder gives you Data. Turn it into a String with String(decoding: data, as: UTF8.self), and set encoder.outputFormatting = [.prettyPrinted, .sortedKeys] for readable output. In JavaScript the same job is JSON.stringify(value), and in Python json.dumps(value).
Building the same app for Android or the web? The JSON tools below make the matching Kotlin data class, TypeScript interface, C# class, Python dataclass and others from the same sample, so every client uses the same field names.
JSON (JavaScript Object Notation) is a text format for data: objects in curly braces, lists in square brackets, and strings, numbers, true, false and null. Almost every web API uses it because it is small, easy to read, and every language can parse it.
Make a Codable struct that matches the JSON (paste the JSON here to get it), then decode with JSONDecoder().decode(Type.self, from: data).
Encode the value with JSONEncoder, set it as the request's httpBody, set Content-Type to application/json and send it with URLSession.
In Swift, encode with JSONEncoder and use String(decoding: data, as: UTF8.self). In JavaScript use JSON.stringify, and in Python json.dumps.
Use a struct for API models: value types are safer and Codable works the same. Choose a final class only when you need one shared object that several parts of the app change.
No. The code is made in your browser.
Format JSON online: beautify messy JSON with 2 or 4 spaces or tabs, sort keys, minify it to one line and find errors. Free, runs in your browser.
Check if JSON is valid and see the exact line and column of any error, with a hint on how to fix it. A free online JSON validator in your browser.
Paste JSON and get Kotlin data classes for Android, with kotlinx.serialization, Gson or Moshi names, nullable fields and defaults. Free, in your browser.
Convert JSON to null-safe Dart model classes for Flutter, with fromJson, toJson and an optional copyWith. Free, no sign-up, runs in your browser.