When I try to test some JSON in the python interpreter I get the error. I'm not sure why.
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
TypeError: unhashable type: 'dict'
JSON: (doesn't work)
b = {
'data':{
'child':{
{'kid1':'one'},
{'kid2':'two'},
{'kid3':'three'}
},
'child':{
{'kid4':'four'},
{'kid5':'five'},
{'kid6':'six'}
}
}
}
JSON: (works)
a = {
"slate" : {
"id" : {
"type" : "integer"
},
"name" : {
"type" : "string"
},
"code" : {
"type" : "integer",
"fk" : "banned.id"
}
},
"banned" : {
"id" : {
"type" : "integer"
},
"domain" : {
"type" : "string"
}
}
}
The reason your first example doesn't work is that each 'child' key has a dictionary declared as it's value instead of a list, as it looks like you intended. Replace the {
with [
and it will work.
'child': {
{'kid1':'one'},
{'kid2':'two'},
{'kid3':'three'},
},
Should be:
'child': [
{'kid1':'one'},
{'kid2':'two'},
{'kid3':'three'},
],
In other words, you're saying 'child' is a dictionary without giving a dictionary.
This issue came up for me when I had slightly malformed JSON:
json = {
{
"key": "value",
"key_two": "value_two"
}
}
Should be:
json = {
"key": "value",
"key_two": "value_two"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With