[memo] Swift open file and modify

Updated
Oct 8, 2020 6:12 PM
Created
Oct 8, 2020 6:11 PM
Tags
MemoSwift
Keywords
Date

import JAYSON
import Files

do {
  let f = try File(path: "path")

  let data = try f.read()

  var json = try JSON(data: data)

  let source = json.components!.schemas!.dictionary!
  for element in source {
    let newKey = "_tmp_" + element.key
    json["components"]!["schemas"]![element.key] = nil
    json["components"]!["schemas"]![newKey] = element.value
  }

  try f.write( try json.data(options: [.prettyPrinted, .withoutEscapingSlashes]))

} catch let error {
  print(error)
}