Flat and Nested API responses

After a successful connection to the supplier API, Attribute mapping is most important to import products successfully. The API response can be flat (no nesting) or Nested. Below is the difference between flat and non-nested API responses:

Flat

{
  "product_id": "12345",
  "name": "Wireless Headphones",
  "category": "Electronics",
  "brand": "SoundPro",
  "price": 99.99,
  "currency": "USD",
  "stock_quantity": 50,
  "description": "High-quality wireless headphones with noise cancellation and 20-hour battery life.",
  "color": "Black",
  "dimensions": "7.5 x 6.5 x 3.0 inches",
  "weight": "0.5 lbs",
  "rating": 4.5,
  "reviews_count": 120,
  "image_url": "https://example.com/images/headphones.jpg",
  "sku": "SP-WH-1000",
  "release_date": "2023-05-10",
  "tags": ["wireless", "headphones", "noise-cancelling", "Bluetooth"]
}

In Flat API responses, you can directly map the attributes. Example

  • For SKU map product_id
  • For Name map name and similarly for all other attributes.
  • If the value of any attribute in API response is an array, like that of tags in above example, you can either assign the whole array by mapping tags, or any element like tags->0 for wireless and tags->2 for noise-cancelling.

Nested

{
  "product_id": "12345",
  "name": "Wireless Headphones",
  "category": "Electronics",
  "brand": "SoundPro",
  "description": "High-quality wireless headphones with noise cancellation and 20-hour battery life.",
  "pricing": {
    "price": 99.99,
    "currency": "USD",
    "discount": {
      "is_discounted": true,
      "discount_percentage": 10,
      "discount_price": 89.99,
      "start_date": "2023-11-01",
      "end_date": "2023-12-31"
    },
    "pricing_tiers": [
      {
        "tier_name": "Standard",
        "min_quantity": 1,
        "price_per_unit": 99.99
      },
      {
        "tier_name": "Bulk",
        "min_quantity": 5,
        "price_per_unit": 89.99
      }
    ]
  },
  "stock": {
    "total_quantity": 150,
    "locations": [
      {
        "location_id": "NYC-01",
        "stock_quantity": 60,
        "region": "New York",
        "warehouse_name": "NYC Warehouse"
      },
      {
        "location_id": "LA-02",
        "stock_quantity": 40,
        "region": "California",
        "warehouse_name": "LA Warehouse"
      },
      {
        "location_id": "TX-03",
        "stock_quantity": 50,
        "region": "Texas",
        "warehouse_name": "TX Warehouse"
      }
    ]
  },
  "product_details": {
    "color": "Black",
    "dimensions": "7.5 x 6.5 x 3.0 inches",
    "weight": "0.5 lbs",
    "rating": 4.5,
    "reviews_count": 120,
    "release_date": "2023-05-10",
    "sku": "SP-WH-1000",
    "image_url": "https://example.com/images/headphones.jpg"
  },
  "variations": [
    {
      "variation_id": "1",
      "color": "Black",
      "price": 99.99,
      "stock_quantity": 60,
      "sku": "SP-WH-1000-BLACK",
      "image_url": "https://example.com/images/black_headphones.jpg",
      "features": {
        "battery_life": "20 hours",
        "noise_cancellation": "Yes",
        "connectivity": "Bluetooth 5.0"
      }
    },
    {
      "variation_id": "2",
      "color": "White",
      "price": 109.99,
      "stock_quantity": 40,
      "sku": "SP-WH-1000-WHITE",
      "image_url": "https://example.com/images/white_headphones.jpg",
      "features": {
        "battery_life": "20 hours",
        "noise_cancellation": "Yes",
        "connectivity": "Bluetooth 5.0"
      }
    },
    {
      "variation_id": "3",
      "color": "Blue",
      "price": 99.99,
      "stock_quantity": 50,
      "sku": "SP-WH-1000-BLUE",
      "image_url": "https://example.com/images/blue_headphones.jpg",
      "features": {
        "battery_life": "20 hours",
        "noise_cancellation": "Yes",
        "connectivity": "Bluetooth 5.0"
      }
    }
  ],
  "reviews": {
    "average_rating": 4.5,
    "total_reviews": 120,
    "user_reviews": [
      {
        "review_id": "r001",
        "user_id": "user123",
        "rating": 5,
        "comment": "Excellent headphones with great sound quality and comfort!",
        "date": "2023-06-15"
      },
      {
        "review_id": "r002",
        "user_id": "user456",
        "rating": 4,
        "comment": "Good sound, but a bit tight on the ears after long use.",
        "date": "2023-07-10"
      }
    ]
  },
  "tags": ["wireless", "headphones", "noise-cancelling", "Bluetooth"],
  "warranty": {
    "duration": "1 year",
    "coverage": "Manufacturing defects only",
    "terms": "https://example.com/warranty-terms"
  }
}

In Nested API responses, you can map the attributes with the help of -> Example:

  • If you want to map price which is inside the pricing object {}, you can map it like pricing->price.
  • If you want to assign the user reviews comment, you can map reviews->user_reviews->0->comment.
  • In nut shell, if you want to get inside a json object you need to include -> and if it is an array you need to use the element position number as well.