Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Best way to expose existing pages as JSON?

Avatar

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
therealsatz
Level 2

02-01-2019

Hi Guys, we have an existing website containing more than 2000 pages and we are looking as exposing the content as a service so that they can be consumed by an external mobile app.

1. I have tried looking at CaaS feature available OOTB in 6.4 but that requires us to create content fragments but we already have 2000 pages which needs to be exposed for a mobile app

2. I've also looked at JSON Exporter which works with the suffic ".model.json". This gives some json data but its not really usable since it is more of a dump of the jcr structure and also misses some important page content like Text, Images etc.

So apart from the above two options, do we have anything else that would fit the use case? We would just need our page content like text, images etc. to be exposed to be used by a 3rd party mobile application.

Replies

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,086 likes

Total Posts

3,121 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,086 likes

Total Posts

3,121 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

03-01-2019

Regarding your approach 2): If you get the JCR properties as well, you are the seeing the output of the Default Get Servlet (in JSON format). This is the generic fallback of all requests to .json files. But this also means that you don't have a ModelExporter registered for this page.

To make the SlingModelExporter work, you can check the documentation at [1].

Jörg

[1] Adobe Experience Manager Help | Developing Sling Model Exporters in AEM

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

441 likes

Total Posts

1,016 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

441 likes

Total Posts

1,016 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

03-01-2019

Did u think about writing a custom servlet which will help you expose your content in your required format ?

Avatar

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

19 likes

Total Posts

51 posts

Correct Reply

7 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

19 likes

Total Posts

51 posts

Correct Reply

7 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile
rampai
Level 3

03-01-2019

Try this. It exposes AEM pages as json with the structure exposed as well.

The only known limitation here is that editable templates do not work in this.

Getting Started with AEM Sites - WKND Tutorial

Avatar

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
therealsatz
Level 2

03-01-2019

Thanks for the response Rampai, i do not see anything related to exposing page data as json in the github project you had posted. have you posted the right link?

Avatar

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
therealsatz
Level 2

03-01-2019

Hi Jörg, you were very right about the exporter not being registered. Thanks for that.

with that said, I created a exporter for the model as well but I believe the whole exporter feature works only when we access the components specifically but not for the whole page itself.

What we are trying to achieve is to give some form of meaningful json for a mobile app developer to consume for the whole page and not for specific components.

Avatar

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
therealsatz
Level 2

Likes

4 likes

Total Posts

12 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 3
Boost 1
View profile
therealsatz
Level 2

03-01-2019

Hi Veena, yes we gave that a thought but how well do you think that will work?

Not all our components have sling models associated with them and all our pages follow a different structure, also we have some sling models which has dynamic objects populated from external APIs.

Do do you think there is a simple strategy to get a structured json of a page via a servlet without having to write too much if else conditions taking the various page structures into consideratio?

Avatar

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

19 likes

Total Posts

51 posts

Correct Reply

7 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

19 likes

Total Posts

51 posts

Correct Reply

7 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile
rampai
Level 3

03-01-2019

My Bad. Can you check this instead?

Adobe Experience Manager Help | Getting Started with React and AEM SPA Editor - Chapter 0

The sample pages are exposed by appending .model.json to the pages in the completed solution.

e.g.

To expose data for Page:

http://localhost:4502/content/wknd-events/react/home.html

Use:

http://localhost:4502/content/wknd-events/react/home.model.json

There's one for Angular as well.

Avatar

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

19 likes

Total Posts

51 posts

Correct Reply

7 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Ignite 1
Level 3
rampai
Level 3

Likes

19 likes

Total Posts

51 posts

Correct Reply

7 solutions
Top badges earned
Ignite 1
Validate 1
Give Back 5
Give Back 3
Give Back 10
View profile
rampai
Level 3

03-01-2019

therealsatz​, this is how it looks:

1659960_pastedImage_0.png

1659961_pastedImage_1.png

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,086 likes

Total Posts

3,121 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,086 likes

Total Posts

3,121 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

04-01-2019

If you don't have sling models in place for all components, the only chance you have is just to dump the JCR content structure (and then you don't get the additional semantics which are provided by the model classes, as they know much more about the actual content and its semantic than just the pure repo structure).

Basically this is done by the Default Get Servlet and its JSON rendition, but you can write a custom servlet which does this as well; and there you can omit certain properties from being delivered, e.g "jcr:primaryType" etc.

using OSGI r6 anotations it can look like this:

@Component(service=Servlet.class)

@SlingServletResourceTypes(

  resourceTypes="cq/Page",

  selectors="dump",

  extension="json"

)

public class MyServlet ....

(Apache Sling :: Servlets and Scripts )