{"id":9580,"date":"2024-07-24T08:07:17","date_gmt":"2024-07-24T08:07:17","guid":{"rendered":"https:\/\/axamit.com\/?post_type=glossary-article&#038;p=9580"},"modified":"2024-08-16T14:01:40","modified_gmt":"2024-08-16T14:01:40","slug":"json-responses","status":"publish","type":"glossary-article","link":"https:\/\/axamit.com\/glossary\/aem\/json-responses\/","title":{"rendered":"Exploring JSON Responses in Adobe Experience Manager (AEM)"},"content":{"rendered":"<div class=\"custom-toc\"><ul><\/ul><\/div>\n<p class=\"wp-block-paragraph\">Adobe Experience Manager&nbsp;(AEM) is a powerful content management system that provides a robust and flexible framework for delivering content. One of the ways AEM can deliver content is in the form of JSON responses. This guide will explain how to get a JSON response from AEM.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key Takeaways<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JSON, or JavaScript Object Notation, is a lightweight data-interchange format that\u2019s easy to read and write.<\/li>\n\n\n\n<li>AEM can deliver content as a JSON response, which can be useful for RESTful services, Single Page Applications (SPAs), or any client that can consume JSON.<\/li>\n\n\n\n<li>You can get a JSON response from AEM by appending <strong>.json<\/strong> to the path of a resource in the URL.<\/li>\n\n\n\n<li>The content of the JSON response can be controlled using selectors and suffixes in the URL.<\/li>\n\n\n\n<li>Sling\u00a0Models Exporter feature in AEM can be used to customize the JSON output.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What is JSON?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JSON (JavaScript Object Notation) is a popular data format with diverse uses in data interchange, including configuration, data storage, and data communication between a server and client. JSON provides a human-readable collection of data that we can access in a logical manner.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use JSON in AEM?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In AEM, JSON can be used to programmatically retrieve structured content. Applications that consume JSON data include Single Page Applications (SPAs), mobile apps, or other third-party applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting a JSON Response<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Getting a JSON response in AEM is straightforward. Simply append <strong>.json<\/strong>&nbsp;to the path of a resource in your&nbsp;AEM instance&nbsp;URL. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:4502\/content\/we-retail\/us\/en.model.json<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will return the content of the resource as a JSON response.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Customizing the JSON Response<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can control the depth of the JSON response by adding a selector that specifies the depth. For example, to get a JSON response with a depth of 2 levels, you would use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:4502\/content\/we-retail\/us\/en.model.2.json<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using Sling Models Exporter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AEM provides the Sling Models Exporter feature, which allows you to customize the JSON output by creating a&nbsp;Sling Model&nbsp;and using the <strong>@Exporter<\/strong>&nbsp;annotation. This can be particularly useful when you need a specific structure for your JSON response.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the Implications<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Knowing how to get and customize a JSON response in AEM has several implications:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Integration<\/strong>: JSON responses can be consumed by various clients including SPAs, mobile apps, and other&nbsp;third-party services.<\/li>\n\n\n\n<li><strong>Development<\/strong>: <a href=\"https:\/\/axamit.com\/adobe-experience-cloud\/adobe-experience-manager\/hire-aem-developers\/\">AEM developers<\/a> can programmatically retrieve and manipulate content.<\/li>\n\n\n\n<li><strong>Performance<\/strong>: JSON is a lightweight data format, which can lead to faster data retrieval and improved performance.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Getting a JSON response in AEM is an essential skill for developers working with AEM, especially when integrating AEM with other applications. This technique enables the structured retrieval of content from AEM, which can be streamlined and manipulated to fit the needs of your application. After understanding this, you can explore more advanced topics like creating custom exporter with Sling Models Exporter or integrating AEM with SPAs. Remember, effective use of JSON responses in AEM requires a strong understanding of AEM\u2019s content structure, and a careful approach to data modeling.<\/p>\n","protected":false},"author":12,"featured_media":5015,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"glossary-category":[43],"class_list":["post-9580","glossary-article","type-glossary-article","status-publish","has-post-thumbnail","hentry","glossary-category-aem"],"acf":{"post_title":"JSON Responses"},"_links":{"self":[{"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/glossary-article\/9580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/glossary-article"}],"about":[{"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/types\/glossary-article"}],"author":[{"embeddable":true,"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/users\/12"}],"version-history":[{"count":4,"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/glossary-article\/9580\/revisions"}],"predecessor-version":[{"id":9742,"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/glossary-article\/9580\/revisions\/9742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/media\/5015"}],"wp:attachment":[{"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/media?parent=9580"}],"wp:term":[{"taxonomy":"glossary-category","embeddable":true,"href":"https:\/\/axamit.com\/pl\/wp-json\/wp\/v2\/glossary-category?post=9580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}