Last active
September 27, 2024 20:37
-
-
Save WFT/8c293ee16362dd2262d0e5a00998e3a7 to your computer and use it in GitHub Desktop.
Reads a plist with top-level dictionary and converts to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Reads a plist with top-level dictionary and converts to JSON. JSON printed to stdout. | |
// Run like this: `swift plist-to-json.swift myplist.plist` | |
guard CommandLine.arguments.count == 2 else { | |
let msg = "Usage: \(CommandLine.arguments[0]) <path-to-input.plist>\n" | |
try FileHandle.standardError.write(contentsOf: Data(msg.utf8)) | |
exit(1) | |
} | |
let dict = try NSDictionary(contentsOf: URL(fileURLWithPath: CommandLine.arguments[1]), error: ()) | |
let data = try JSONSerialization.data(withJSONObject: dict, options: [.prettyPrinted, .withoutEscapingSlashes, .sortedKeys]) | |
try FileHandle.standardOutput.write(contentsOf: data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment