Easy JSON parsing with Codable

Tudip Technologies
1 min readOct 29, 2021

--

Swift codable protocol has a combination of Encodable and Decodable protocol that can be used to work with JSON data in both directions. In short, Swift Codable protocol has offered the following features:

  • Using Codable, by writing very few lines of code, we can model JSONObject or PropertyList file into equivalent struct or classes. For the properties in the objects we don’t have to write the constructor. Codable hands it all. We simply need to extend our model to conform to the protocol for coding, decoding or encoding.
  • Swift compiler handled the mismatch between the strong data types of Swift and lose data types of JSON internally. We can now manage types of Swift Data such as Date, URL, Float, etc. Complex JSON can be easily modelled using readability Nesting Structs.
  • Complex JSON can be easily modelled using readability Nesting Structs.
  • Use JSONDecoder to parse actual JSON to become one-liner.

Now Let’s Get Into The Fun Part of coding

There is an API for displaying Zomato cities, and the endpoint is for Pune:

If you want to try you can try that out on link.

Read more: https://tudip.com/blog-post/easy-json-parsing-with-codable/

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response