for feature in features_selected:
    item = {'id': feature.pk}
for attribute in attributes_selected:
    if attribute.feature == feature:
        item[attribute.attribute.name] = attribute.value
data.append(item)
jsonData = json.dumps(data)
JSON - Generating a json in a loop in python