0

I am wondering how to get all of the sets of numbers that come after "id": on each line of this link using Cheerio in JS: https://kith.com/collections/mens-footwear/products/nkcw7297-100.json

Example:

[{
    "id": 19437838336128,
    "product_id": 2069464547456,
    "title": "3",
    "price": "110.00",
    "sku": "12757001",
    "position": 1,
    "compare_at_price": "",
    "fulfillment_service": "manual",
    "inventory_management": "shopify",
    "option1": "3",
    "option2": null,
    "option3": null,
    "created_at": "2020-07-13T07:24:00-04:00",
    "updated_at": "2020-07-14T08:07:57-04:00",
    "taxable": true,
    "barcode": null,
    "grams": 1361,
    "image_id": null,
    "weight": 3.0,
    "weight_unit": "lb",
    "tax_code": "PC040100",
    "requires_shipping": true
  }, {
    "id": 19437838368896,
    "product_id": 2069464547456,
    "title": "3.5",
    "price": "110.00",
    "sku": "194496645118",
    "position": 2,
    "compare_at_price": "",
    "fulfillment_service": "manual",
    "inventory_management": "shopify",
    "option1": "3.5",
    "option2": null,
    "option3": null,
    "created_at": "2020-07-13T07:24:00-04:00",
    "updated_at": "2020-07-31T17:38:25-04:00",
    "taxable": true,
    "barcode": null,
    "grams": 1361,
    "image_id": null,
    "weight": 3.0,
    "weight_unit": "lb",
    "tax_code": "PC040100",
    "requires_shipping": true
  },

So I'd want to be able to get the 2 variants after "id": at the start of each item. (1st is 19437838336128 & second is 19437838368896 )

Adam Azad
  • 11,171
  • 5
  • 29
  • 70
Salvatore Timpani
  • 407
  • 3
  • 6
  • 26

1 Answers1

1

You don't DOM manipulation for that. You can use fetch (use node.js polyfill);

fetch('https://kith.com/collections/mens-footwear/products/nkcw7297-100.json')
.then(res => res.json())
.then(data => {

    let variantsIds = data.product.variants.map(p => p.id);

})
.catch(console.log)
Adam Azad
  • 11,171
  • 5
  • 29
  • 70