1

I want to find id and options in this JSON data. Here's What I did so far.

data = """
      "list": null,
      "promotionID": "",
      "isFreeShippingApplicable": true,
      "html": "\n\n\n<div class=\"b-product-tile-price\">\n    \n    \n\n\n\n<span class=\"b-product-tile-price-outer\">\n    <span class=\"b-product-tile-price-item\">\n        1200 &euro;\n\n\n    </span>\n</span>\n\n</div>\n\n"
    },
    "longDescription": "<ul>\n\t<li>STYLE:&nbsp;BQ4420-100</li>\n\t<li>Laufsohle: Gummi</li>\n\t<li>Obermaterial: beschichtetes Leder, Textil</li>\n\t<li>Innenmaterial: Textil</li>\n</ul>\n",
    "shortDescription": null,
    "availability": {
      "messages": [
        "Sofort lieferbar"
      ],
      "inStockDate": null,
      "custom": {
        "code": null,
        "label": null,
        "orderable": true,
        "sizeSelectable": true,
        "badge": false

"""

find_values = json.loads(data)
id = find_values["id"]
variables = find_product_data["variables"]
print(id, variables)

The output is an erro but when I try to get the values of first the attribute action, it gets returned but not the others.

1 Answer 1

2

You can't access the id directly, because it is nested inside another dictionary. What you have to do is get that dict first and then access the id.

find_values = json.loads(data)
product = find_values["product"]
id_value = product("id")

If you are working with an IDE it could help to debug your code and see how the dict is actually nested.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.