When data come from JSON in the format below, I can turn it into a dictionary in Python. However, the information is not always in the same order. For instance, first_name
, I would assume is always 0. However, when I get the data, depending on the form used, may be in the 2 position. So now, instead of storing first_name
in the right db field, it may be in the email
field.
Here's my question: how do I ensure the value matches the db field using the name
key, value?
{
"name": "first_name",
"values": [
"Joe"
]
},
{
"name":"last_name",
"values": [
"Example"
]
},
{
"name": "email",
"values": [
"joe@example.com"
]
}
Thank you, as always! :-)
Update Here's how I access the code:
first_name = data['field_data'][0]['values'][0].encode('utf-8')
last_name = data['field_data'][1]['values'][0].encode('utf-8')
email = data['field_data'][2]['values'][0].encode('utf-8')
telephone = data['field_data'][3]['values'][0].encode('utf-8')
I'm making the assumption that first_name
will always be at 0, even though that's not the case. The Python saves the data, it's putting emails in places where first_name should be. I'm trying to find a way to verify the JSON name
key corresponds with the same db field before submitting the data.