Skip to main content

JSON

JSON is the default language of web APIs. Prism makes it easy to decode incoming JSON and send JSON responses using Swift’s Codable system.

Sending JSON Responses

JSON Response
With a Codable struct:
Codable Response

Decoding JSON Requests

Decode Request Body

Complete REST API Example

Todo API
Use Decodable for request types (you only need to decode) and Codable for response types (you only need to encode). Using the narrower protocol makes your intent clear.

Custom JSON Encoder

Custom Date Format