Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

data-sly-list iteration for a JsonArray

Avatar

Level 2
 
 

Hi AEM Gurus,

 

I have a JSON Array like below sample

 

 

{
"sites": {
"label": "Parent LABEL",
"mobileLabel": "Parent Mobile Label",
"items": [
{
"href": "www.google.com",
"id": "goog",
"label": "Google Search"
},
{
"href": "www.yahoo.com",
"id": "yah",
"label": "yahoo site"
},
{
"href": "www.wikipedia.com",
"id": "wiki",
"label": "wikipedia"
}
]
}
}

Now i am trying to Iterate and get the values from this JSON array using data-sly-list something like as shown in below structure

<ul data-sly-list.key="${model.jsonarray}">
<li><a  href="${key.href}">${key.label} - ${key.id}</a></li>
</ul>

I know we can iterate Arraylist or a Map object but how do I iterate a JSON array. Please suggest.

 

Regards,

Rajashankar.R

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor and Adobe Champion

You would need to serialize the JSON string to either a List<HashMap> or List<Link>. Once you return a valid List object to your slightly business logic, your code should work as expected. 

However, if your list looks something like List<Json> then that would also work as well. You ultimately just need to have a valid List object with valid item objects.

View solution in original post

19 Replies

Avatar

Correct answer by
Community Advisor and Adobe Champion

You would need to serialize the JSON string to either a List<HashMap> or List<Link>. Once you return a valid List object to your slightly business logic, your code should work as expected. 

However, if your list looks something like List<Json> then that would also work as well. You ultimately just need to have a valid List object with valid item objects.

Avatar

Level 2
Hi Brian,

Avatar

Community Advisor

Hi @rajaram33,

 

You can use the below code, convert JSONArray to List and pass it to sightly.

 

ArrayList<String> listdata = new ArrayList<String>();
if (jArray != null) {
for (int i=0;i<jArray.length();i++){
listdata.add(jArray.getString(i));
}
}

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

Avatar

Level 2
Let me try both options and get back soon please do not close this as resolved

Avatar

Level 2
I tried adding Json Array to array list but when i try to access it in htl like this <div class="cmp-helloworld__item" data-sly-use.model="com.demoapp.core.models.FooterModel"> <ul data-sly-list.child="${model.demoItem}"> <li > ${child.label} Value: ${child.href}</li> </ul> </div>

Avatar

Level 2
Kiran please suggest how to parse the list in this case in htl which has the json array populated at model.I am struglling at htl to get the value

Avatar

Level 2
 

Hi @BrianKasingli @Kiran_Vedantam ,

I tried as suggested by creating a Link with hashmap

 

 

public List<HashMap<String, String>> getListItem(JSONObject taxanomyDat) {
log.info("Inside Model getDemoItem");

List<HashMap<String, String>> prodArrayList = new ArrayList<HashMap<String, String>>();

Map<String, String> siteLink = new LinkedHashMap<String, String>();

siteLink.put("label1", "www.gmail.com");
siteLink.put("label2", "www.yahoo.com");
prodArrayList.add((HashMap<String, String>) siteLink);

return prodArrayList;
}

public List<HashMap<String, String>> getDemoItem() {
return demoItem;
}

 

 

And in HTL i am not sure What mistake i am doing or how to get the key and value inside haspmap of arraylist.

 

 

<div class="cmp-helloworld__item" data-sly-use.model="com.myapp.core.models.SampleModel">
<p class="cmp-helloworld__item-label">Model message:</p>
<ul data-sly-list="${model.demoItem}">
<li >${item.siteLink}</li>
</ul>
</div>

 

 

 

 

 

 

 

 

 

 

Avatar

Community Advisor and Adobe Champion

Avatar

Level 1

Hi AEM Gurus,

 

I have a JSON Array like below sample

 

 

{
"sites": {
"label": "Parent LABEL",
"mobileLabel": "Parent Mobile Label",
"items": [
{
"href": "profile bio ",
"id": "goog",
"label": "Google Search"
},
{
"href": "profile bio /",
"id": "yah",
"label": "yahoo site"
},
{
"href": "www.wikipedia.com",
"id": "wiki",
"label": "wikipedia"
}
]
}
}

Now i am trying to Iterate and get the values from this JSON array using data-sly-list something like as shown in below structure

<ul data-sly-list.key="${model.jsonarray}">
<li><a  href="${key.href}">${key.label} - ${key.id}</a></li>
</ul>

I know we can iterate Arraylist or a Map object but how do I iterate a JSON array. Please suggest.

 

Regards,

Rajashankar.R

Avatar

Level 1

Hi AEM Gurus,

 

I have a JSON Array like below sample

 

 

{
"sites": {
"label": "Parent LABEL",
"mobileLabel": "Parent Mobile Label",
"items": [
{
"href": "picpalace ",
"id": "goog",
"label": "Google Search"
},
{
"href": "picpalace",
"id": "yah",
"label": "yahoo site"
},
{
"href": "www.wikipedia.com",
"id": "wiki",
"label": "wikipedia"
}
]
}
}

Now i am trying to Iterate and get the values from this JSON array using data-sly-list something like as shown in below structure

<ul data-sly-list.key="${model.jsonarray}">
<li><a  href="${key.href}">${key.label} - ${key.id}</a></li>
</ul>

Our collection of good morning monday images has the ideal visual to meet all your needs – from inspiring quotes and humorous quips to relaxing images

I know we can iterate Arraylist or a Map object but how do I iterate a JSON array. Please suggest.

 

Regards,

Rajashankar.R

Avatar

Level 1


"href": "godimagesdownload",

"href": "godimagesdownload",
ction of Waheguru Good Morning Images  has the ideal visual to meet all your needs – from inspiring quotes and humorous quips to relaxing images

 

Avatar

Level 1

Our collection of good morning monday images has the ideal visual to meet all your needs – from inspiring quotes and humorous quips to relaxing images

Avatar

Level 1

I have a JSON Array like below sample

 

 

{
"sites": {
"label": "Parent LABEL",
"mobileLabel": "Parent Mobile Label",
"items": [
{
"href": "www.google.com",
"id": "goog",
"label": "Google Search"
},
{
"href": "www.yahoo.com",
"id": "yah",
"label": "yahoo site"
},
{
"href": "www.wikipedia.com",
"id": "wiki",
"label": "wikipedia"
}
]
}
}

Now i am trying to Iterate and get the values from this JSON array using data-sly-list something like as shown in below structure

<ul data-sly-list.key="${model.jsonarray}">

Our collection of good morning monday images has the ideal visual to meet all your needs – from inspiring quotes and humorous quips to relaxing images

Avatar

Level 1

Capture Your Special Moments with Our Best Wedding Photography in Delhi NCR ! Your wedding day is a once-in-a-lifetime event, and we’re here to capture every precious moment. Our talented photographers specialize in creating timeless images that tell your unique love story. Serving all areas of Delhi NCR, including South, East, Central Delhi, and Noida, we offer a wide range of services to fit your needs. Whether it's an intimate ceremony or a grand reception, we focus on preserving every detail for you to cherish forever. From professional wedding photography to pre-wedding shoots, our team ensures your special day is captured beautifully. We also offer destination wedding photography, bringing our expertise to any location.

 

Avatar

Level 1

Staffing Solutions

 

download.jpg

 

At MNR Solutions, we focus on delivering competency-based and quality staffing solutions driven by dynamic business needs across the multi-industry sectors. From timely temporary staffing on quick projects to permanent staffing for long-term organizational success and executive staffing for strategic firms, our staffing services will provide you with all the staffing solutions you require.

Unlock your potential with Success Point College’s Master of Business Administration (MBA) program, designed for aspiring professionals and business leaders. Our MBA program in dubai , available to students in both Sharjah and Dubai, offers a comprehensive curriculum that equips you with advanced skills in management, strategy, finance, and leadership.

Avatar

Level 1

Welcome to Sai CPA – Your Trusted Accounting Partner

At Sai CPA, we understand that managing finances, taxes, and compliance requirements can be overwhelming. With years of expertise in accounting, tax preparation, auditing, and financial consulting, we provide businesses and individuals with the highest level of professional financial services. CPA firm new jersey

Why Choose Sai CPA?

  1. Expertise You Can Trust
    Our team of certified public accountants (CPAs) has extensive experience in handling tax planning, business accounting, and financial management for individuals, startups, and established businesses.

  2. Personalized Financial Solutions
    We recognize that every client has unique financial goals. That’s why we provide customized tax and accounting strategies to help you maximize savings and ensure financial stability.

  3. Comprehensive Tax Services
    Whether you need assistance with income tax filing, tax resolution, corporate tax strategies, or IRS representation, our team is here to guide you through the complexities of tax laws while ensuring compliance with the latest regulations.

  4. Bookkeeping & Payroll Management
    Maintaining accurate financial records is crucial for the success of any business. We offer bookkeeping, payroll processing, and financial reporting services to keep your operations running smoothly.

  5. Audit & Assurance Services
    Our audit services help businesses maintain financial transparency and comply with industry regulations. We conduct independent audits and internal reviews to enhance financial credibility.

  6. Business Consulting & Entity Formation
    If you're starting a new business, we provide guidance on business entity selection, financial planning, and strategic growth planning, ensuring you start on a strong foundation.

Industries We Serve

We cater to a wide range of industries, including:

Small Businesses & Startups
Real Estate & Construction
Healthcare & Medical Professionals
E-commerce & Retail
Non-Profit Organizations
Professional Services

Get in Touch Today!

At Sai CPA, our goal is to simplify your financial journey and help you make informed decisions that drive growth and success. Whether you need tax assistance, accounting support, or financial consulting, we are here to help!

Avatar

Level 1

Welcome to Sai CPA Services, a top CPA firm in New Jersey, and a leading accounting services provider in Middlesex County, New Jersey. We assist individuals and companies with financial planning, tax preparation, and accounting. Our team of Certified Public Accountants provides various solutions to help you confidently handle financial challenges.

 

At Sai CPA Services, we believe that our clients’ success is our success. That’s why we work closely with you to understand your unique financial situation and develop customized solutions that meet your specific needs. Whether you’re a small business owner or an individual looking to manage your personal finances, we are here to help.

Avatar

Level 1

Thanks for stopping by InTown Photography, we are the best wedding photographers in Delhi NCR and have been for over 13 years. We have serviced and continue offering our photography services in Noida, Gurugram, Ghaziabad, Faridabad and other parts of Delhi NCR. Apart from being a leading wedding and pre-wedding photographer, we care about capturing the most cherished moments from your life with lots of creativity, accuracy, and love.