JSON Formatter for Swift
Free online json formatter with Swift code examples
Working with json formatter in Swift? Our free online json formatter helps Swift developers format, validate, and process data instantly. Below you will find Swift code examples using Foundation (built-in) so you can achieve the same result programmatically in your own projects.
Try the JSON Formatter Online
Use our free JSON Formatter directly in your browser — no setup required.
Open JSON FormatterSwift Code Example
import Foundation
let json = #"{"name":"Alice","age":30}"#.data(using: .utf8)!
let parsed = try JSONSerialization.jsonObject(with: json)
let formatted = try JSONSerialization.data(
withJSONObject: parsed,
options: .prettyPrinted
)
print(String(data: formatted, encoding: .utf8)!)Quick Setup
Library: Foundation (built-in)
// Built-in framework — no installation neededSwift Tips & Best Practices
- Use .prettyPrinted option for formatted output
- Prefer Codable protocol for typed Swift structs
- JSONDecoder/JSONEncoder is more Swifty than JSONSerialization