0

I have to prepare JSON files to send using POST, but I have faced the following format to handle:

offer { 
         "location":
         {
         "city": "Kharkov",
         "address": "street"
         }
         "dates": [
         {
            "start_date": "2018-10-10 14:00",
            "end_date": "2018-11-11 14:00"
         }]
}

Before it, to set the Value for the city field I used the following implementation:

offer['location']['city'] = "Kharkov"

But now I can't figure out how to add the value to the key start_date since the dictionary is inside the list.

0

1 Answer 1

1

'dates' is a list. Use index to access the key inside.

Ex:

offer['dates'][0]["start_date"] = "NewDate"
print(offer)

Output:

{'dates': [{'start_date': 'NewDate', 'end_date': '2018-11-11 14:00'}], 'location': {'city': 'Kharkov', 'address': 'street'}}
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.