Skip to content

Switch to using JSONEncoder.makeWithDefaults() for JSON output of describe command #3087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions Sources/Commands/Describe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,8 @@ func describe(_ package: Package, in mode: DescribeMode, on stream: OutputByteSt
let data: Data
switch mode {
case .json:
let encoder = JSONEncoder()
let encoder = JSONEncoder.makeWithDefaults()
encoder.keyEncodingStrategy = .convertToSnakeCase
// FIXME: This should be extracted into somewhere reusable.
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
encoder.outputFormatting = [.sortedKeys, .prettyPrinted, .withoutEscapingSlashes]
}
else if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
encoder.outputFormatting = [.sortedKeys, .prettyPrinted]
}
else {
encoder.outputFormatting = [.prettyPrinted]
}
data = try! encoder.encode(desc)
case .text:
var encoder = PlainTextEncoder()
Expand Down