NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

need to find out what is wrong with my JSON

Forums > Swift

I am creating a multiple choice quiz with a JSON file I created. I took some code from the 100 days of SwiftUI tutorial to decode it. There is obviously something wrong with my JSON because the fatal error is thrown. How can I find out what the error is with my JSON? The code I used is below: extension Bundle { func decode<T: Codable>(_ file: String) -> T { guard let url = self.url(forResource: file, withExtension: nil) else { fatalError("Failed to locate (file) in bundle.") }

    guard let data = try? Data(contentsOf: url) else {
        fatalError("Failed to load \(file) from bundle.")

    let decoder = JSONDecoder()

    guard let loaded = try? decoder.decode(T.self, from: data) else {

        fatalError("Failed to decode \(file) from bundle.")


    return loaded


Please post a sample of your JSON and the data structure you are trying to decode it into.


Subscribe to Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

Not logged in

Log in

Link copied to your pasteboard.