I am working with a Harp project, using Jade templates. I have my _data.json
populated with content and I'm having trouble accessing it the way I thought I could. Given this JSON structure:
{
"mountain-residence": {
"slug": "mountain-residence",
"title": "Mountain Residence",
"lead": "A southeast facing home...",
"thumb": "exterior/entry",
"sections": [
{
"exterior": {
"slug": "exterior",
"title": "Exterior Photos",
"lead": "Embracing an entry...",
"thumb": "terrace",
"photos": [
{
"slug": "southeast",
"alt": "Mountain Room Overlook",
"caption": "Porch, deck and spa terrace"
},
{
"slug": "terrace",
"alt": "Southeast Terrace",
"caption": "Spa deck and landscape terrace"
},
{
"slug": "entry",
"alt": "Entry Courtyard",
"caption": "Entry court and pergola"
},
{
"slug": "porch",
"alt": "Entry Porch",
"caption": "Timber entry shelter"
}
]
}
},
{
"interior": {
"slug": "interior",
"title": "Interior Photos",
"lead": "The interior spaces...",
"thumb": "mountain-room2",
"photos": [
{
"slug": "mountain-room2",
"caption": "Entry opening to the Mountain Room"
},
{
"slug": "dining",
"caption": "Dining Room into Mountain Room"
},
{
"slug": "cellar1",
"caption": "Wine Cellar and Tasting Room"
},
{
"slug": "den",
"caption": "Den and Family Hearth"
}
]
}
},
{
"design-sketches": {
"slug": "design-sketches",
"title": "Design Sketches",
"lead": "A careful site...",
"thumb": "shower",
"photos": [
{
"slug": "schematic",
"caption": "Exterior Elevation Study"
},
{
"slug": "elevation",
"caption": "Elevation Color Studies"
},
{
"slug": "shower",
"caption": "Outdoor stone shower"
}
]
}
}
]
}
}
I cannot figure out how to access a named object within an array, like mountain-residence.sections.exterior.title
("Exterior Photos"). Trying mountain-residence.sections['exterior'].title
doesn't work either. I can access the same property with mountain-residence.sections[0].title
, and my JSON seems to be valid, but I need to call the object with its name... Is there a way to do this?
For example, "mountain-residence"
populates a page, and my general idea was to have each object in "sections"
populate its own sub-page, which is why I want to be able to call it up by name through my JSON.