Not sure how to use a tuple as a set of strings the way I would like.
I would like my json to look like:
'item': {
'a': {
'b': {
'c': 'somevalue'
}
}
}
Which could be done with:
item = {}
item['a']['b']['c'] = "somevalue"
However a
, b
, and c
are dynamic, so I understand I need to use a tuple
, but this does not do what I would like:
item = {}
path = ('a','b','c')
item[path] = "somevalue"
json.dump(item, sys.stdout)
So I am getting the error:
TypeError("key " + repr(key) + " is not a string"
How do I dynamically get item['a']['b']['c']
?