-
-
Save haikusw/eb629d31e0fcdb28263258ff7ec94502 to your computer and use it in GitHub Desktop.
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 SwiftUI | |
import Yams | |
extension String { | |
var yamlToJSON: String { | |
do { | |
guard let parsed = try Yams.load(yaml: self) else { return "" } | |
let data = try JSONSerialization.data(withJSONObject: parsed, options: [.sortedKeys, .prettyPrinted]) | |
return String(decoding: data, as: UTF8.self) | |
} catch { | |
return "\(error)" | |
} | |
} | |
} | |
@main | |
struct YamlToJSONApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
} | |
} | |
struct ContentView: View { | |
@State var input = "" | |
var body: some View { | |
HSplitView { | |
TextEditor(text: $input) | |
TextEditor(text: .constant(input.yamlToJSON)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/helje5 commented:
As a swift-sh script: