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

  • Possible duplicate of [Django template how to look up a dictionary value with a variable](https://stackoverflow.com/questions/8000022/django-template-how-to-look-up-a-dictionary-value-with-a-variable) – Brown Bear Sep 25 '18 at 09:49

1 Answers1

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 %}
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895