Java: JSON to Map

We can construct a Map<String, Object> from a JSON string with the help of reflect:

1
2
3
4
5
6
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

var mapType = new TypeToken<Map<String, Object>>() {
}.getType();
Map<String, Object> myMap = new Gson().fromJson(jsonString, mapType);