I am just starting to play around with APIs and I have a list of products I want to pull from a clients website. Everything is working fine but I realized that the way they return their URLs will not work if I upload them directly to a database because they have a "//" in front of it and browsers automatically assume its a file instead of https://. I am trying to loop through the returned value and search for all URLs and delete // or add https: to the front of it. Notice all the URLs show up in the lists nested inside the JSON
Currently I have written code that can loop through the current JSON, but the structure of the JSON is not always the same and the keys change depending on the category of product or even the product. I'd like to be able to loop through the JSON, determine if it is a list, loop through that, and change the URL and SRC keys. Unless there is another way to go about this!
"category": "Thermostats",
"description": {
"long": "The ultimate controller for precise comfort",
"short": "Ultra Smart Thermostat"
},
"disclaimers": [
{
"body": "S30 is compatible with Lennox HVAC products and requires separate purchase of Amazon Echo or Echo Dot. At this time, Amazon asserts that Amazon Echo devices are not available for purchase in all countries. Therefore, this reference is intended for use with US-based thermostats only. Amazon, Alexa and all related logos are trademarks of Amazon.com, Inc. or its affiliates.",
"id": 54
},
{
"body": "Apple HomeKit technology provides an easy, secure way to control your home\u2019s lights, doors, thermostats, and more from your iPhone, iPad, or Apple Watch. To control this HomeKit-enabled accessory, iOS 10.2.1 or later is recommended. Apple, Apple Watch, iPad, iPad Air, iPhone, and iPod touch are trademarks of Apple Inc., registered in the U.S. and other countries. HomeKit is a trademark of Apple Inc.",
"id": 56
}
],
"efficiencies": null,
"energyStarQualified": false,
"energyStarSouthQualified": false,
"formattedModelNumber": "iComfort S30",
"id": 190,
"image": {
"default": {
"alt": "iComfort S30\u00ae Ultra Smart Thermostat",
"src": "//resources.lennox.com/fileuploads/e5cef8c9-67f6-479e-83f2-f56d2e067850cgi63393_main_default.png"
},
"lg": {
"alt": "iComfort S30\u00ae Ultra Smart Thermostat",
"src": "//resources.lennox.com/fileuploads/682ef372-b8cd-4866-a1f0-088482d57b29cgi63393_main_lg.png"
},
"md": {
"alt": "iComfort S30\u00ae Ultra Smart Thermostat",
"src": "//resources.lennox.com/fileuploads/29c45676-ba25-4743-ba23-ac1042359136cgi63393_main_md.png"
},
"sm": null,
"x-lg": null,
"x-sm": null
},
"isLimitedAvailability": false,
"limitedAvailabilityContent": null,
"limitedAvailabilityLinkText": null,
"literature": [
{
"title": "iComfort Smart Thermostats Product Brochure",
"type": "Product Brochure",
"url": "//resources.lennox.com/fileuploads/a196ddc3-0959-4433-9f37-b07147d3d418LennoxiComfortThermostats.pdf"
},
{
"title": "iComfort S30 Product Brochure",
"type": "Product Brochure",
"url": "//resources.lennox.com/fileuploads/e0c68728-91f3-4de7-8872-065c850aa9faiComfortS30_Product_Brochure.pdf"
},
{
"title": "iComfort S30 Homeowner Manual",
"type": "Homeowners Manual",
"url": "//resources.lennox.com/fileuploads/706b3305-e698-4f44-bc3c-764c144d74beiComfort%20_S30_%20Homeowner_Manual.pdf"
},
{
"title": "iComfort S30 Installation Manual and Setup Guide",
"type": "Installation Manual",
"url": "//resources.lennox.com/fileuploads/b9863d33-f22e-4fc2-ae10-0a143901528bLennox_iComfortS30_Installation_Manual_Setup_Guide.pdf"
},
{
"title": "Ultimate Comfort System Products Brochure",
"type": "System Literature",
"url": "//resources.lennox.com/fileuploads/dc0c5077-c8ea-4933-87f3-1facef93f38b10D29_UCS_84800_0516.pdf"
}
],
"modelName": "iComfort\u00ae S30 Ultra Smart Thermostat",
"modelNumber": "iComfort S30",
"priceGuide": "$$$$",
"series": "None",
"solarReady": false,
"supportImage": {
"default": {
"alt": "living room",
"src": "//resources.lennox.com/fileuploads/b8ea938d-c4c4-4838-9e64-acd137b30ce3s30-promo-default.jpg"
},
"lg": {
"alt": "living room",
"src": "//resources.lennox.com/fileuploads/1ff69e07-90bf-4f73-8bb5-8288e5c417f1s30-promo-lg.jpg"
},
"md": {
"alt": "living room",
"src": "//resources.lennox.com/fileuploads/64d481eb-80a1-469d-b473-b2d2d505238es30-promo-md.jpg"
},
"sm": null,
"x-lg": null,
"x-sm": null
},
"taxCreditQualifying": false,
"warrantyBlurb": "5-Year Limited Warranty",
"warrantyEligible": false
}
json.loads, right? Can you share some code snippet?