Read & Parse local JSON file in Swift


  1. Build model for your json data.

  "firstname": "Emrah",
  "lastname": "Turan",
  "website": ""

struct DataModel: Codable {
    var firstname: String
    var lastname: String
    var website: String
  1. Create a function to call your json file. Give json filename and model as parameter.

private func getData(completion: @escaping(DataModel?) -> Void) {
        readFromFile(fileName: "data", completion: completion)
  1. Data read from json file is ready to be used.

getData { data in
        guard let data = data else { return }

        print("firstname: ", data.firstname)
        print("lastname: ", data.lastname)
        print("website: ",


If you have feedback about my ReadJsonFile Project do not forget to reach me via email or Discussions section of this repo.


View Github