Question: I am trying to figure out the best way to go about this. I am converting a library to typescript and am running into one particular issue which I've had before. There is a function who's definition looks a bit like this

```
public execute(path: string | string[]): Promise<Object> {
  if (typeof path == "string") {
    // Turn the string into an array
  }
}

```

The problem is I can't convert the path parameter into an array because it is of the type `(string | string[])`. Also trying to do this fails.

```
public execute(path: string | string[]): Promise<Object> {
  newPath: string[];
  if (typeof path == "string") {
    newPath = [path];
  } else {
    newPath = path;
  }
}

```

Because path is of the type `(string | string[])` and cannot be assigned to type `string[]`. Any solutions?

Answer: 
Don't know if it matters for performance, but you shouldn't call `names()` repeatedly. Assign to variable before loop, then use it.

```
JSONArray names = airports.names();
Log.d("Length Array 0", String.valueOf(names.length()));
Log.d("Length Array 1", String.valueOf(arrayAirports.size()));
for(int i = 0; i<names.length(); i++){
    JSONObject jsonAirport = airports.getJSONObject(names.getString(i));
    // code
}

```

**Better yet, use `length()` and `keys()`:**

```
Log.d("Length Array 0", String.valueOf(airports.length()));
Log.d("Length Array 1", String.valueOf(arrayAirports.size()));
for (Iterator<String> nameIter = airports.keys(); nameIter.hasNext(); ){
    String name = nameIter.next();
    JSONObject jsonAirport = airports.getJSONObject(name);
    // code
}

```
Use [GSON](https://github.com/google/gson) instead and measure the speed with it. While it is possible possible that just reading the file could take a long time, a whole minute seems pretty bad.

Since you mentioned you don't know how to use GSON, [here's a tutorial I wrote for a student on how to use GSON](http://toomanytutorials.blogspot.com/2016/02/deserialize-json-data-returned-from.html). It assume you're getting the file from a network call though, so you need to apply it to use your local JSON file.