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

Returning list of pages at given path in JSON format.

Avatar

Avatar
Boost 1
Level 1
vivekanandu8544
Level 1

Like

1 like

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
vivekanandu8544
Level 1

Like

1 like

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile
vivekanandu8544
Level 1

03-10-2018

Hi Team,

I have a requirement where I need to return list of pages available at given path. This service should return json structure, which would return name and title of the each page.

Any help would be greatly appreciated.

Thanks in advance.

Replies

Avatar

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

124 likes

Total Posts

203 posts

Correct Reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 1
MVP
raj_mandalapu
MVP

Likes

124 likes

Total Posts

203 posts

Correct Reply

72 solutions
Top badges earned
Validate 1
Contributor
Shape 1
Give Back 5
Give Back 3
View profile
raj_mandalapu
MVP

03-10-2018

You need to iterate child pages and export in the form of JSON, if you are familiar with sling models then you can use sling model exporter, check below link

http://keysandstrokes.info/aem-code-snippets-export-page-data-as-json-format-using-sling-model-expor...

Approach 2:

Pass page path as a parameter to the servlet and in the servlet iterate child pages and using Gson convert that into JSON format. you need to Json mime type to see the output in JSON format when we request servlet

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,356 likes

Total Posts

3,227 posts

Correct Reply

917 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,356 likes

Total Posts

3,227 posts

Correct Reply

917 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

03-10-2018

Hi,

You can try with QueryBuilder Debugger

e.g.

http://localhost:4502/bin/querybuilder.json?p.hits=selective&p.limit=-1&p.properties=jcr%3acontent%2...

http://localhost:4502/libs/cq/search/content/querydebug.html

Query

path=/content/

type=cq:Page

p.hits=selective

p.properties=jcr:content/jcr:title jcr:path

p.limit=-1

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

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

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

471 likes

Total Posts

1,039 posts

Correct Reply

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

03-10-2018

Apart from above solution I might go for below approach.

1) Send the path as parameter to your request

2) In the servlet/service , iterate the children

3) I will have a POJO like below to populate the children

public class Document {

     private String name;

     private String title;

     ....

    <getter and setter for both >

}

4) While iterating , add the name and title and form a list of this POJO .

5) Once the iteration is complete , convert the POJO to JSON using GSON API

  If you need more details do let me know

Thanks

Veena