How to access multiple nested objects when the nested object name is variable

I may not be using terminology correctly in the way I’m describing this so hopefully it makes sense. The issue I’m having is I believe I have a js response where there is an object nested within an object, but it is not an array. I want to access a property called sellerName within the nested object, but the nested object name is variable. Here is a snippet to show the parent child relationship but the full response is pasted further down in this post.

"sellers":
{
"A1RBSEPX566CDE":
{
"trackedSince":
5539522,
"domainId":
1,
"sellerId":
"A1RBSEPX566CDE",
"sellerName":
"APT Group LLC",
"csv":

The part that is giving me a headache is the “A1RBSEPX566CDE” which is a sellerId and changes within the “sellers” object, where there is many.But I want to access the sellerName within that “A1RBSEPX566CDE” object. I provide a response below with two sellers and you can see both in that response.

Since it is not an array it does not appear that item lists works. And I cannot figure out how to do a for loop on a repeating nested object where the name of that object keeps changing.

So for example, something like this does not work in extracting a single value, {{ $json[“sellers”][0][“sellerName”] }}, but this does work using the SET node, {{ $json[“sellers”][“A119MICOGEUS26”][“sellerName”] }} … because I’m referencing the exact object name.

But I can’t use SET because I want to access all sellerNames within the response which is multiple, not a single sellerName.

There is not much of a workflow to show because all I have at this point is a response using HTTPS, but I have attached a sample response.

I believe I’ll need to use the code node but not sure how I’d write this for loop given it’s not an array. Any assistance is appreciated.

If I try to use Item Lists, I’ll get error “fieldToSplitOut.includes is not a function”

Please share the workflow

Share the output returned by the last node

[{
    "timestamp": 1669808314358,
    "tokensLeft": 298,
    "refillIn": 59430,
    "refillRate": 5,
    "tokenFlowReduction": 0,
    "tokensConsumed": 2,
    "processingTimeInMs": 1,
    "sellers": {
        "A1RBSEPX566CDE": {
            "trackedSince": 5539522,
            "domainId": 1,
            "sellerId": "A1RBSEPX566CDE",
            "sellerName": "APT Group LLC",
            "csv": [
                [
                    5596800,
                    100,
                    5689370,
                    75
                ],
                [
                    5596800,
                    1,
                    5663856,
                    2
                ]
            ],
            "lastUpdate": 6266058,
            "isScammer": false,
            "hasFBA": true,
            "totalStorefrontAsins": [
                6245256,
                38
            ],
            "sellerCategoryStatistics": [{
                    "catId": 172282,
                    "productCount": 20,
                    "avg30SalesRank": 36580,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "catId": 7141123011,
                    "productCount": 14,
                    "avg30SalesRank": 95754,
                    "productCountWithAmazonOffer": 6
                },
                {
                    "catId": 1055398,
                    "productCount": 13,
                    "avg30SalesRank": 207492,
                    "productCountWithAmazonOffer": 3
                },
                {
                    "catId": 3760901,
                    "productCount": 4,
                    "avg30SalesRank": 105435,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "catId": 15684181,
                    "productCount": 2,
                    "avg30SalesRank": 60635,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "catId": 165793011,
                    "productCount": 2,
                    "avg30SalesRank": 74268,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "catId": 228013,
                    "productCount": 2,
                    "avg30SalesRank": 373,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "catId": 468642,
                    "productCount": 2,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 2
                },
                {
                    "catId": 10272111,
                    "productCount": 1,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "catId": 16310091,
                    "productCount": 1,
                    "avg30SalesRank": 113292,
                    "productCountWithAmazonOffer": 0
                }
            ],
            "sellerBrandStatistics": [{
                    "brand": "dyson",
                    "productCount": 7,
                    "avg30SalesRank": 270475,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "sonos",
                    "productCount": 7,
                    "avg30SalesRank": 55551,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "seagate",
                    "productCount": 6,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "puma",
                    "productCount": 4,
                    "avg30SalesRank": 28115,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "brand": "champion",
                    "productCount": 3,
                    "avg30SalesRank": 1812,
                    "productCountWithAmazonOffer": 3
                },
                {
                    "brand": "nike",
                    "productCount": 3,
                    "avg30SalesRank": 508951,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "carole hochman",
                    "productCount": 2,
                    "avg30SalesRank": 43702,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "cat",
                    "productCount": 2,
                    "avg30SalesRank": 60635,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "google",
                    "productCount": 2,
                    "avg30SalesRank": 373,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "brand": "meta quest",
                    "productCount": 2,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 2
                }
            ],
            "shipsFromChina": false,
            "address": [
                "2514 Colliford Creek CT",
                "Katy",
                "TX",
                "77494-3718",
                "US"
            ],
            "recentFeedback": [{
                    "rating": 10,
                    "date": 6230880,
                    "feedback": "I bought this product and had it delivered 10/8/22. Just ran out of my last bottle so opened this bottle. Seal was intact. Every pill inside the bottle was oily... I bought this product and had it delivered 10/8/22. Just ran out of my last bottle so opened this bottle. Seal was intact. Every pill inside the bottle was oily. I dumped them onto a plate to see if I could find a broken pill, but could not. I’ve tried to go the proper route of contacting someone for a replacement but I’m getting nowhere. Hopefully someone is able to respond to me from here. Read more Read less",
                    "isStriked": true
                },
                {
                    "rating": 50,
                    "date": 6219360,
                    "feedback": "all went great.",
                    "isStriked": false
                },
                {
                    "rating": 50,
                    "date": 6206400,
                    "feedback": "Fast and efficient. Thanks",
                    "isStriked": false
                },
                {
                    "rating": 50,
                    "date": 6202080,
                    "feedback": "Oooooooo",
                    "isStriked": false
                },
                {
                    "rating": 50,
                    "date": 6190560,
                    "feedback": "Fast shipping, fair price",
                    "isStriked": false
                }
            ],
            "lastRatingUpdate": 6266058,
            "neutralRating": [
                -1,
                0,
                0,
                0
            ],
            "negativeRating": [
                -1,
                0,
                0,
                0
            ],
            "positiveRating": [
                -1,
                100,
                100,
                100
            ],
            "ratingCount": [
                0,
                12,
                53,
                58
            ],
            "asinList": ,
            "asinListLastSeen": ,
            "totalStorefrontAsinsCSV": ,
            "currentRating": 100,
            "currentRatingCount": 58,
            "ratingsLast30Days": 0
        },
        "A119MICOGEUS26": {
            "trackedSince": 2860408,
            "domainId": 1,
            "sellerId": "A119MICOGEUS26",
            "sellerName": "3 Elements Co",
            "csv": [
                [
                    2860408,
                    94,
                    2935396,
                    93
                ],
                [
                    2860408,
                    963,
                    2867350,
                    964
                ]
            ],
            "lastUpdate": 6266104,
            "isScammer": false,
            "hasFBA": true,
            "totalStorefrontAsins": [
                6222580,
                14
            ],
            "sellerCategoryStatistics": [{
                    "catId": 172282,
                    "productCount": 6,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "catId": 16310101,
                    "productCount": 5,
                    "avg30SalesRank": 14390,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "catId": 228013,
                    "productCount": 1,
                    "avg30SalesRank": 4450,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "catId": 2335752011,
                    "productCount": 1,
                    "avg30SalesRank": 21687,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "catId": 3760901,
                    "productCount": 1,
                    "avg30SalesRank": 1578,
                    "productCountWithAmazonOffer": 1
                }
            ],
            "sellerBrandStatistics": [{
                    "brand": "gigabyte",
                    "productCount": 3,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "kirkland signature",
                    "productCount": 2,
                    "avg30SalesRank": 8048,
                    "productCountWithAmazonOffer": 2
                },
                {
                    "brand": "seagate",
                    "productCount": 2,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "arlo",
                    "productCount": 1,
                    "avg30SalesRank": 4450,
                    "productCountWithAmazonOffer": 1
                },
                {
                    "brand": "belkin",
                    "productCount": 1,
                    "avg30SalesRank": 21687,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "ferrero rocher",
                    "productCount": 1,
                    "avg30SalesRank": 31665,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "golden island",
                    "productCount": 1,
                    "avg30SalesRank": 8719,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "st michel",
                    "productCount": 1,
                    "avg30SalesRank": 11083,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "starbucks",
                    "productCount": 1,
                    "avg30SalesRank": 5965,
                    "productCountWithAmazonOffer": 0
                },
                {
                    "brand": "toshiba",
                    "productCount": 1,
                    "avg30SalesRank": 0,
                    "productCountWithAmazonOffer": 1
                }
            ],
            "shipsFromChina": false,
            "address": [
                "2445 Huntington Dr",
                "#107",
                "San Marino",
                "CA",
                91108,
                "US"
            ],
            "recentFeedback": [{
                    "rating": 50,
                    "date": 6249600,
                    "feedback": "item as described by the seller and brand new",
                    "isStriked": false
                },
                {
                    "rating": 50,
                    "date": 6245280,
                    "feedback": "Nice and effective",
                    "isStriked": false
                },
                {
                    "rating": 10,
                    "date": 6240960,
                    "feedback": "They do not proactively respond to any questions or concerns also did not want to refund me. No worries tho",
                    "isStriked": false
                },
                {
                    "rating": 10,
                    "date": 6160320,
                    "feedback": "Ordered N300 drives and received X300 drives. They're completely different classes of drives.",
                    "isStriked": true
                },
                {
                    "rating": 10,
                    "date": 6134400,
                    "feedback": "0 out 0, you can't possible package an HDD like this, and put it in a BAG, OMG Geez. I'm returning this, and please look at how is being packaged, watch and lea... 0 out 0, you can't possible package an HDD like this, and put it in a BAG, OMG Geez. I'm returning this, and please look at how is being packaged, watch and learn. Read more Read less",
                    "isStriked": true
                }
            ],
            "lastRatingUpdate": 6266104,
            "neutralRating": [
                0,
                0,
                6,
                2
            ],
            "negativeRating": [
                33,
                33,
                18,
                6
            ],
            "positiveRating": [
                67,
                67,
                76,
                92
            ],
            "ratingCount": [
                3,
                3,
                17,
                1967
            ],
            "asinList": ,
            "asinListLastSeen": ,
            "totalStorefrontAsinsCSV": ,
            "currentRating": 92,
            "currentRatingCount": 1967,
            "ratingsLast30Days": 3
        }
    }
}]

Information on your n8n setup

  • n8n version: 0.201.0
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]:

Hi @JasonA, so you essentially want to access each element under sellers in your workflow as an individual item?

If so, I think this would do the job:

In this code snippet, I am using Object.keys() to read all keys of the sellers field, then add a single n8n item for each of them to my results.

Hope this helps!

1 Like

@MutedJam This is perfect. Thank You.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.