Question: I have a JSON file that was filtered and lost the original structure. Each line of the file looks like this:

```
{u'spec1': {u'property1': u'12345', u'property2': 1234}, u'spec2': {u'property3': u'98754', u'property4': u'val1'}}

```

`json.loads` doesn't work and `ast.literal_eval` doesn't work. I guess I have 2 issues: remove unicode and change ' to ". Can anyone provide some pointers on where to start?

Answer: 
At the time of writing, the other answers on this page used old Swift syntax. This is an update.

Convert Optional String to Int: `String? -> Int`
================================================

```
let optionalString: String? = "100"
if let string = optionalString, let myInt = Int(string) {
     print("Int : \(myInt)")
}

```

This converts the string `"100"` into the integer `100` and prints the output. If `optionalString` were `nil`, `hello`, or `3.5`, nothing would be printed.

Also consider using a [`guard` statement](https://thatthinginswift.com/guard-statement-swift/).
Try this:

```
if let i = str_VAR?.toInt() {
    println("\(i)")
}

```