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: 
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.
You are putting a (I guess?) large JSON data file into a JSONObject directly.

In this case it would be recommended to use a token based reader, such as [JsonReader](http://developer.android.com/reference/android/util/JsonReader.html).

Pasted directly from the docs:

```
public List readJsonStream(InputStream in ) throws IOException {
    JsonReader reader = new JsonReader(new InputStreamReader( in , "UTF-8"));
    try {
        return readMessagesArray(reader);
        finally {
            reader.close();
        }
    }

    public List readMessagesArray(JsonReader reader) throws IOException {
        List messages = new ArrayList();

        reader.beginArray();
        while (reader.hasNext()) {
            messages.add(readMessage(reader));
        }
        reader.endArray();
        return messages;
    }

    public Message readMessage(JsonReader reader) throws IOException {
        long id = -1;
        String text = null;
        User user = null;
        List geo = null;

        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("id")) {
                id = reader.nextLong();
            } else if (name.equals("text")) {
                text = reader.nextString();
            } else if (name.equals("geo") && reader.peek() != JsonToken.NULL) {
                geo = readDoublesArray(reader);
            } else if (name.equals("user")) {
                user = readUser(reader);
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        return new Message(id, text, user, geo);
    }

    public List readDoublesArray(JsonReader reader) throws IOException {
        List doubles = new ArrayList();

        reader.beginArray();
        while (reader.hasNext()) {
            doubles.add(reader.nextDouble());
        }
        reader.endArray();
        return doubles;
    }

    public User readUser(JsonReader reader) throws IOException {
        String username = null;
        int followersCount = -1;

        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("name")) {
                username = reader.nextString();
            } else if (name.equals("followers_count")) {
                followersCount = reader.nextInt();
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        return new User(username, followersCount);
    }
}

```