find the extension of a json file in swift

You can find the extension of a JSON file in Swift by using the pathExtension property of URL. Here's an example:

main.swift
let fileURL = URL(fileURLWithPath: "/path/to/file.json")
let ext = fileURL.pathExtension

if ext == "json" {
    print("The file is a JSON file")
} else {
    print("The file is not a JSON file")
}
198 chars
9 lines

In this example, replace "/path/to/file.json" with the path to your JSON file. The pathExtension property returns the extension of the file, which is then compared to "json" to determine if it's a JSON file.

related categories

gistlibby LogSnag