{"id":60883,"date":"2024-03-21T11:50:30","date_gmt":"2024-03-21T06:20:30","guid":{"rendered":"https:\/\/2thenew.xyz\/blog\/?p=60883"},"modified":"2024-06-10T15:32:24","modified_gmt":"2024-06-10T10:02:24","slug":"enhancing-json-response-dynamically-in-aem-with-sling-filters","status":"publish","type":"post","link":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/","title":{"rendered":"Enhancing JSON Response Dynamically in AEM with Sling Filters"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I&#8217;ll walk you through our solution using Sling Filters in AEM, along with code snippets to illustrate the implementation.<\/span><\/p>\n<h2><strong>Understanding the Requirement<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Our requirement was to augment the main JSON response with additional data fetched from a URL provided within the response. Essentially, we needed to append the response from this URL to the main JSON structure before sending it back to the client.<\/span><\/p>\n<h2><strong>Solution Overview<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">To achieve this dynamic modification of the JSON response, we leveraged Sling Filters in AEM. Sling Filters allow us to intercept requests and responses in AEM, making them a perfect fit for our use case. Here&#8217;s an overview of the solution:<\/span><\/p>\n<ol>\n<li><b> Identify the URL within the JSON response:<\/b><span style=\"font-weight: 400;\"> We first needed to parse the incoming JSON response to locate the URL that contains the additional data we want to append.<\/span><\/li>\n<li><b> Implement a Sling Filter:<\/b><span style=\"font-weight: 400;\"> We created a custom Sling Filter that intercepts the request and response. Within this filter, we extracted the URL from the JSON response and made an HTTP request to fetch the additional data.<\/span><\/li>\n<li><b> Append data to the main JSON response: <\/b><span style=\"font-weight: 400;\">Once we retrieved the additional data from the URL, we appended it to the main JSON response.<\/span><\/li>\n<li><b> Return the modified JSON response: <\/b><span style=\"font-weight: 400;\">Finally, we returned the modified JSON response to the client.<\/span><\/li>\n<\/ol>\n<h2><strong>Implementation Steps<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Let&#8217;s dive into the implementation details with code snippets:<\/span><\/p>\n<ol>\n<li><b> Create the Sling Filter<\/b><\/li>\n<\/ol>\n<pre><span style=\"font-weight: 400;\">@Component<\/span><span style=\"font-weight: 400;\">(service = Filter.class, immediate = <\/span><span style=\"font-weight: 400;\">true<\/span><span style=\"font-weight: 400;\">, name = <\/span><span style=\"font-weight: 400;\">\"TTN Custom JSON Filter\"<\/span><span style=\"font-weight: 400;\">, property = {<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">EngineConstants.SLING_FILTER_SCOPE + <\/span><span style=\"font-weight: 400;\">\"=\"<\/span><span style=\"font-weight: 400;\"> + \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\"> \u00a0 \u00a0 \u00a0 EngineConstants.FILTER_SCOPE_REQUEST,<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">EngineConstants.SLING_FILTER_METHODS + <\/span><span style=\"font-weight: 400;\">\"=\"<\/span><span style=\"font-weight: 400;\"> + METHOD_GET,<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">EngineConstants.SLING_FILTER_PATTERN + <\/span><span style=\"font-weight: 400;\">\"=\"<\/span><span style=\"font-weight: 400;\"> + <\/span><span style=\"font-weight: 400;\">\"\/content\/ttn\/api\/v1\/offers\"<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">EngineConstants.SLING_FILTER_SELECTORS + <\/span><span style=\"font-weight: 400;\">\"=\"<\/span><span style=\"font-weight: 400;\"> + model,<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">EngineConstants.SLING_FILTER_EXTENSIONS + <\/span><span style=\"font-weight: 400;\">\"=\"<\/span><span style=\"font-weight: 400;\"> + <\/span><span style=\"font-weight: 400;\">\"json\"<\/span><span style=\"font-weight: 400;\"> })<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">class<\/span> <span style=\"font-weight: 400;\">CustomJsonFilter<\/span> <span style=\"font-weight: 400;\">implements<\/span> <span style=\"font-weight: 400;\">Filter<\/span><span style=\"font-weight: 400;\"> {<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">@Reference<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">private<\/span><span style=\"font-weight: 400;\"> HttpClient httpClient;<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">@Override<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">void<\/span> <span style=\"font-weight: 400;\">doFilter<\/span><span style=\"font-weight: 400;\">(ServletRequest request, ServletResponse response, FilterChain chain) <\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">throws<\/span><span style=\"font-weight: 400;\"> IOException, ServletException {<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">try<\/span><span style=\"font-weight: 400;\"> {<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">apiUrlResponseMap = <\/span><span style=\"font-weight: 400;\">new<\/span><span style=\"font-weight: 400;\"> HashMap&lt;&gt;();<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">SlingHttpServletResponse modelResponse = <\/span><span style=\"font-weight: 400;\">new<\/span><span style=\"font-weight: 400;\"> \u00a0 offerSlingModelResponseWrapper((SlingHttpServletResponse) response);<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">chain.doFilter(slingRequest, modelResponse);<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">PrintWriter responseWriter = response.getWriter();<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">updateJson(modelResponse.toString(), responseWriter);<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">} <\/span><span style=\"font-weight: 400;\">catch<\/span><span style=\"font-weight: 400;\"> (ServletException | IOException e) {<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">logger.error(<\/span><span style=\"font-weight: 400;\">\"doFilter: Exception Occurred: {}\"<\/span><span style=\"font-weight: 400;\">, e.getMessage());<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">}<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\/**<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\"> * Iterates the json response of cms api<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\"> * <\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\"> * @param modelResponse\u00a0 the response object<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\"> * @param responseWriter the printWriter object<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\"> *\/<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">protected<\/span> <span style=\"font-weight: 400;\">void<\/span> <span style=\"font-weight: 400;\">updateJson<\/span><span style=\"font-weight: 400;\">(String modelResponse, PrintWriter responseWriter) {<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">\/\/ write down the logic to update the json response<\/span><span style=\"font-weight: 400;\">\r\n<\/span> <span style=\"font-weight: 400;\">}<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">@Override<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">void<\/span> <span style=\"font-weight: 400;\">init<\/span><span style=\"font-weight: 400;\">(FilterConfig filterConfig) <\/span><span style=\"font-weight: 400;\">throws<\/span><span style=\"font-weight: 400;\"> ServletException {<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\/\/ Do nothing<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">@Override<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">void<\/span> <span style=\"font-weight: 400;\">destroy<\/span><span style=\"font-weight: 400;\">() {<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\/\/ Cleanup logic<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">}<\/span><\/pre>\n<ol start=\"2\">\n<li><b> Implement HTTP Client Service<\/b><\/li>\n<\/ol>\n<pre><span style=\"font-weight: 400;\">\/**<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\"> * Http Request Data Service component that returns the API response in String<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\"> *<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\"> *\/<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">@Component<\/span><span style=\"font-weight: 400;\">(service = HttpRequestDataService.class, immediate = <\/span><span style=\"font-weight: 400;\">true<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">public<\/span> <span style=\"font-weight: 400;\">class<\/span> <span style=\"font-weight: 400;\">HttpRequestDataServiceImpl<\/span> <span style=\"font-weight: 400;\">implements<\/span> <span style=\"font-weight: 400;\">HttpRequestDataService<\/span><span style=\"font-weight: 400;\"> {<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">@Override<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">public<\/span><span style=\"font-weight: 400;\"> String <\/span><span style=\"font-weight: 400;\">invokeHttpRequest<\/span><span style=\"font-weight: 400;\">(URL endpointUrl) {<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\/\/ Make HTTP request to fetch additional data<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\/\/ Return response body as String<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\">\r\n<\/span><span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">By utilizing Sling Filters in AEM, we successfully achieved dynamic modification of JSON responses based on specific criteria. This approach not only met our requirement but also demonstrated the flexibility and extensibility of AEM in handling diverse use cases.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I&#8217;ll walk you through [&hellip;]<\/p>\n","protected":false},"author":1745,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":244,"footnotes":""},"categories":[5868,4488],"tags":[4847,5008,1521,5720],"class_list":["post-60883","post","type-post","status-publish","format-standard","hentry","category-adobe","category-web-content-management","tag-aem","tag-aemaacs","tag-sling","tag-slingfilters"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I&#039;ll walk you through\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Karansheel Bhardwaj\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I&#039;ll walk you through\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I&#039;ll walk you through\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#article\",\"name\":\"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog\",\"headline\":\"Enhancing JSON Response Dynamically in AEM with Sling Filters\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/karansheel-bhardwaj\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2024-03-21T11:50:30+05:30\",\"dateModified\":\"2024-06-10T15:32:24+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#webpage\"},\"articleSection\":\"Adobe, Web Content Management, AEM, AEMaaCS, sling, SlingFilters\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/web-content-management\\\/#listItem\",\"name\":\"Web Content Management\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/web-content-management\\\/#listItem\",\"position\":2,\"name\":\"Web Content Management\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/web-content-management\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#listItem\",\"name\":\"Enhancing JSON Response Dynamically in AEM with Sling Filters\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#listItem\",\"position\":3,\"name\":\"Enhancing JSON Response Dynamically in AEM with Sling Filters\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/web-content-management\\\/#listItem\",\"name\":\"Web Content Management\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/karansheel-bhardwaj\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/karansheel-bhardwaj\\\/\",\"name\":\"Karansheel Bhardwaj\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/d235d5e9-ca45-4ce8-99c5-9a499878c597_Karansheel-Bhardwaj-Profile-Pitcure.jpeg\",\"width\":96,\"height\":96,\"caption\":\"Karansheel Bhardwaj\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/\",\"name\":\"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog\",\"description\":\"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I'll walk you through\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/enhancing-json-response-dynamically-in-aem-with-sling-filters\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/karansheel-bhardwaj\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/karansheel-bhardwaj\\\/#author\"},\"datePublished\":\"2024-03-21T11:50:30+05:30\",\"dateModified\":\"2024-06-10T15:32:24+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog","description":"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I'll walk you through","canonical_url":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#article","name":"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog","headline":"Enhancing JSON Response Dynamically in AEM with Sling Filters","author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/karansheel-bhardwaj\/#author"},"publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"},"datePublished":"2024-03-21T11:50:30+05:30","dateModified":"2024-06-10T15:32:24+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#webpage"},"isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#webpage"},"articleSection":"Adobe, Web Content Management, AEM, AEMaaCS, sling, SlingFilters"},{"@type":"BreadcrumbList","@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","position":1,"name":"Home","item":"https:\/\/2thenew.xyz\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/web-content-management\/#listItem","name":"Web Content Management"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/web-content-management\/#listItem","position":2,"name":"Web Content Management","item":"https:\/\/2thenew.xyz\/blog\/category\/web-content-management\/","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#listItem","name":"Enhancing JSON Response Dynamically in AEM with Sling Filters"},"previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#listItem","position":3,"name":"Enhancing JSON Response Dynamically in AEM with Sling Filters","previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/web-content-management\/#listItem","name":"Web Content Management"}}]},{"@type":"Organization","@id":"https:\/\/2thenew.xyz\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/2thenew.xyz\/blog\/"},{"@type":"Person","@id":"https:\/\/2thenew.xyz\/blog\/author\/karansheel-bhardwaj\/#author","url":"https:\/\/2thenew.xyz\/blog\/author\/karansheel-bhardwaj\/","name":"Karansheel Bhardwaj","image":{"@type":"ImageObject","@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/d235d5e9-ca45-4ce8-99c5-9a499878c597_Karansheel-Bhardwaj-Profile-Pitcure.jpeg","width":96,"height":96,"caption":"Karansheel Bhardwaj"}},{"@type":"WebPage","@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#webpage","url":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/","name":"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog","description":"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I'll walk you through","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/#breadcrumblist"},"author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/karansheel-bhardwaj\/#author"},"creator":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/karansheel-bhardwaj\/#author"},"datePublished":"2024-03-21T11:50:30+05:30","dateModified":"2024-06-10T15:32:24+05:30"},{"@type":"WebSite","@id":"https:\/\/2thenew.xyz\/blog\/#website","url":"https:\/\/2thenew.xyz\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog","og:description":"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I'll walk you through","og:url":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/","og:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Enhancing JSON Response Dynamically in AEM with Sling Filters | TO THE NEW Blog","twitter:description":"In the realm of web development, customizing JSON responses dynamically based on specific criteria is a common requirement. Recently, our team encountered such a scenario in Adobe Experience Manager (AEM) where we needed to modify the JSON response based on a URL value within the response itself. In this blog post, I'll walk you through","twitter:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"60883","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2024-03-20 05:13:01","updated":"2024-03-21 06:20:32","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\/category\/web-content-management\/\" title=\"Web Content Management\">Web Content Management<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tEnhancing JSON Response Dynamically in AEM with Sling Filters\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/2thenew.xyz\/blog"},{"label":"Web Content Management","link":"https:\/\/2thenew.xyz\/blog\/category\/web-content-management\/"},{"label":"Enhancing JSON Response Dynamically in AEM with Sling Filters","link":"https:\/\/2thenew.xyz\/blog\/enhancing-json-response-dynamically-in-aem-with-sling-filters\/"}],"_links":{"self":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/60883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/users\/1745"}],"replies":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/comments?post=60883"}],"version-history":[{"count":3,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/60883\/revisions"}],"predecessor-version":[{"id":60894,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/60883\/revisions\/60894"}],"wp:attachment":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/media?parent=60883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/categories?post=60883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/tags?post=60883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}