Skip to content

Commit

Permalink
Sort JSON keys if macOS version allows it.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerluan committed Feb 17, 2021
1 parent 1e65bda commit 3271dae
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/SwiftInfoCore/FileUtils/FileUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ public struct FileUtils {
let path = try outputFileURL()
log("Path to save: \(path.absoluteString)", verbose: true)
let dictionary = ["data": output]
let json = try JSONSerialization.data(withJSONObject: dictionary, options: [.prettyPrinted])
let writingOptions: JSONSerialization.WritingOptions = {
if #available(OSX 10.13, *) {
return [.prettyPrinted, .sortedKeys]
} else {
return [.prettyPrinted]
}
}()
let json = try JSONSerialization.data(withJSONObject: dictionary, options: writingOptions)
try? fileManager.createDirectory(atPath: try outputFileFolder(),
withIntermediateDirectories: true,
attributes: nil)
Expand Down

0 comments on commit 3271dae

Please sign in to comment.