class QueryUtil {

    public static Map<String, Object> toMap(JSONObject object) throws JSONException
    {
        Map<String, Object> map = new HashMap<>();
        Iterator<String> keysItr = object.keys();
        while (keysItr.hasNext())
        {
            String key = keysItr.next();
            Object value = object.get(key);

            if (value instanceof JSONArray)
            {
                value = toList((JSONArray) value);
            }

            if (value instanceof JSONObject)
            {
                value = toMap((JSONObject) value);
            }

            map.put(key, value);
        }
        return map;
    }

    private  QueryUtil();

}