I have a dict that I want to convert in JSON using simplejson.
How can I ensure that all the keys of my dict are lowercase ?
{
"DISTANCE": 17.059918745802999,
"name": "Foo Bar",
"Restaurant": {
"name": "Foo Bar",
"full_address": {
"country": "France",
"street": "Foo Bar",
"zip_code": "68190",
"city": "UNGERSHEIM"
},
"phone": "+33.389624300",
"longitude": "7.3064454",
"latitude": "47.8769091",
"id": "538"
},
"price": "",
"composition": "",
"profils": {},
"type_menu": "",
"ID": ""
},
EDIT: Thanks all to had a look at my question, I am sorry I didn't explain in detailed why I wanted this. It was to patch the JSONEmitter
of django-piston
.
Here is a solution that forbids setting a lowercase key:
Here is my solution :
If you just want to check if they're all lowercase (your wording, using "ensure", is not clear, but I suspect this isn't what you want), you can do that compactly in one line:
Here is a complete solution
Or if you want to see the code:
Since you have not mentioned clearly what you want to do:
Convert all keys to lowercase:
Check for keys: