0

How can we parse json array of objects in python. I have the ff code below in getting the data. How to parse it where in we can load the p_id and item_name on the tempalte select option value ?

products = requests.get('http://123.89.166.42:803/api/1.0/data', headers=headers).json()
        context['products'] = products

template :

<select>
          {% for product in products.result %}
          <option value="{{ product.p_id }}">{{ product.item_name }}</option>
          {% endfor %}
      </select>

Data : http://dpaste.com/0BHS9TP

1

1 Answer 1

1

Your JSON does not have a top-level result key. It has a response key, which itself contains a result. So:

{% for product in products.response.result %}
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.