class RestUtils {

    public static JSONObject getTypedObjectFromJsonld(String json, String type) {
        long start = System.currentTimeMillis();
        try {
            List<JSONObject> objects = new ArrayList<>();
            JSONArray array = JSONArray.fromObject(json);

            array.forEach(o -> objects.add(JSONObject.fromObject(o)));

            for (JSONObject o : objects) {
                if (o.isArray()) {
                    o = getTypedObjectFromJsonld(o.toString(), type);
                } else if (o.containsKey("@graph")) {
                    o = getTypedObjectFromJsonld(JSONArray.fromObject(o.get("@graph")).toString(), type);
                }
                if (o != null && o.containsKey("@type") && JSONArray.fromObject(o.get("@type")).contains(type)) {
                    return o;
                }
            }
            return null;
        } finally {
            LOG.trace("getTypedObjectFromJsonld took {}ms", System.currentTimeMillis() - start);
        }
    }

}