You can use SlingRequestProcessor.
http://sling.apache.org/apidocs/sling6/org/apache/sling/engine/SlingRequestProcessor.html
You can try something like the following;
private RequestResponseFactory requestResponseFactory;
private SlingRequestProcessor requestProcessor;
private ResourceResolver resourceResolver;
private JSONObject getResourceJSON(Resource resource, Map<String, Object> anyOtherRequestParams) {
JSONObject jsonObject = null;
String requestURL = null;
try {
requestURL = resource.getPath() + ".json";
HttpServletRequest request = this.requestResponseFactory.createRequest("GET", requestURL, anyOtherRequestParams);
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpServletResponse response = requestResponseFactory.createResponse(out);
this.requestProcessor.processRequest(request, response, this.resourceResolver);
jsonObject = new JSONObject(new String(out.toByteArray(), STRING_ENCODING));
} catch (Exception ex) {
LOGGER.warn("Failed to export resource as JSON " + resource + "," + requestURL, ex);
}
return jsonObject;
}