import com.google.gson.JsonArray import com.google.gson.JsonObject /** * This script will print a JSON array of all namespaces on current AEM instance * Each JSON object in the array will be of the format: * {"prefix":"The namespace prefix", "uri":"The namespace uri"} * */ def reg = session.getWorkspace().getNamespaceRegistry(); def jsonArray = new JsonArray() reg.getPrefixes().each { prefix -> def uri = reg.getURI(prefix) def json = new JsonObject() json.addProperty("prefix", prefix) json.addProperty("uri", uri) jsonArray.add(json) } print jsonArray.toString()